joe_pool_is Posted December 26, 2005 Posted December 26, 2005 I'm trying to create some properties in my C# project, but the IDE (Visual Studio 2005 Express) is very upset and is throwing red squiggle lines underneath items everywhere. I realize the calendar class I am creating is probably done somewhere already, but I want to learn how to do some things with C# during my time off from work (where we are stuck using Borland). Right now, I want to find out how to add a property and how to access indexed property values. // ---------------------------------------- public class Calendoo { private string mName = "blank"; private string[] mMonth = new string[16]; private bool[] mInUse = new bool[16]; public string Name { get { return mName; } set { mName = value; } } public string MonthO(int i) { get { return mMonth[i]; } set { mMonth[i] = value; } } public bool UseO(int i) { get { return mInUse[i]; } set { mInUse[i] = value; } } } // ---------------------------------------- First off, when I hand type in the get/set values, the IDE throws a red squiggle beneath the { and says ; expected. Second, if I hadn't looked at the examples, I would not have known about the secret "value" variable. What would I modify if I wanted to change that to something else (like val, v, or Fred)? Third, the gets mad when I pass values into it, like (int i). How should this be done? Quote Avoid Sears Home Improvement
HJB417 Posted December 26, 2005 Posted December 26, 2005 (edited) C# Language Specification -- 10.6.2 Accessors Long, dry, boring yet complete. you can't rename 'value'. It will always be 'value' inside the set accessor. you can't do (parameter1, parameter2, etc) on properties properties can be Indexers e.x.: public bool this[int i] { get { return mInUse; } set { mInUse = value; } and that's about it. Edited December 26, 2005 by HJB417 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.