Automatic properties are syntactic sugar for properties supported by fields.
Properties are syntactic sugar for setter and / or getter methods.
Therefore, the code you give is more or less equivalent:
private string _name; public string get_Name() { return _name; } private void set_Name(string value) { _name = value; }
Then string val = Obj.Name becomes equivalent to string val = Obj.get_Name() , which can be attached to string val = Obj._name .
Similar code
string val = "Default Name"; if(Obj != null) val = Obj.Name;
Is equivalent to:
string val = "Default Name"; if(Obj != null) val = Obj.get_Name();
What can be attached to:
string val = "Default Name"; if(Obj != null) val = Obj._name;
Please note that private and public apply to compilation, not execution, therefore, if the fact that the support field is private will make Obj._name illegal outside the class in question, the equivalent code created by the attachment is allowed.
Jon hanna
source share