// Define public string name {Get; Set ;}// implicit private string name; Public string name {get {return name;} in the property ;} set {name = value ;}}
Both are used to encapsulate fields for data security.
Normally, the two are used in the same way. The previous method is used by the compiler to generate the latter code;
Public string name {Get; set;} can be written after dotnet2.0 to reduce the workload of programmers.
Of course, if simple get is not implemented by writing, set cannot be implemented by writing. However, if the abstract keyword abstract is added before, the corresponding non-write implementation will be the same as the abstract method;
Get and set can also be added with public and other access levels.
The difference is:
If you want to make some judgment on the attribute, such as the string cannot be empty, the integer must be greater than zero, and so on, you cannot use it.
public string name{get;set;}
Such convenience must be honestly written
public string Name{ get { return name; } set { name= value; }}
Such code