C# Programming
09-26-2009, 08:50 AM
Hello all,
As you may know, in C# 3.0 and later we can add this kind of syntax to a class:
public class CMyClass
{
public int MyIntValue { get; set; }
}
The "get; set;" provides what MSDN documentation refers to as a "trivial" property. That is, there's no extra logic that needs to be applied to either the get or set part of the property. The compiler picks up on this syntax and auto-generates the underlying class member.
My question is: WHY IS THIS USEFUL??? If you have a property that has unrestricted get and set access, how is that any different than just declaring a public class member? Why do I need to waste the extra 13 keystrokes to type:
public int MyIntValue { get; set; }
instead of just:
public int MyIntValue;
To me this seems like an absolutely ridiculous syntax feature. Does anyone have any great insight into this?
As you may know, in C# 3.0 and later we can add this kind of syntax to a class:
public class CMyClass
{
public int MyIntValue { get; set; }
}
The "get; set;" provides what MSDN documentation refers to as a "trivial" property. That is, there's no extra logic that needs to be applied to either the get or set part of the property. The compiler picks up on this syntax and auto-generates the underlying class member.
My question is: WHY IS THIS USEFUL??? If you have a property that has unrestricted get and set access, how is that any different than just declaring a public class member? Why do I need to waste the extra 13 keystrokes to type:
public int MyIntValue { get; set; }
instead of just:
public int MyIntValue;
To me this seems like an absolutely ridiculous syntax feature. Does anyone have any great insight into this?