Possible Duplicate:
Can I create an automatic property (no private member) with get and set code?
Access automatic property – c#
I’ve worked with explicit getters / setters such as
private bool myField;
public bool MyField
{ get { return myField; }
set { myField = value; }
}
Now, working with C# .net 4.0, you have the ability to abbreviate such as
public bool MyField
{ get; set; }
Now, if I want to override only the SET portion, what is the INTERNAL reference I should be referencing… in the first sample, I know I am explicitly referring to the private of “myField”, but with the second version, what am I referencing? Does the compiler just throw an implied “_” such as _MyField as the private side of the element?
whatever the compiler does in this case is an implementation detail which can change in the future without further notice!
Thus I strongly recommend to not make your code depend on such an implementation detail and just use the first option (override both accessors and have field to explicitely back the property) in this case…