Sometimes it is unclear whether a member variable or attribute is used for a class.
For example:
Member variables
Public string Name;
Or use attributes
Private string name
Public string Name
{
Get
{
Return name;
}
Set
{
Name = value;
}
}
Similar to member variables, attributes provide data storage, but attributes are far more powerful than member variables. Properties are accessed by special methods (Get and Set accessors. Get and Set accessors allow property value verification, other code execution, or other tasks after setting or retrieving Properties
For example
Write member variables like this
Public readonly string Name;
It can still be read-only.
Private string name
Public string Name
{
Get
{
Return name;
}
}
Object-Oriented programming methods are abstract and encapsulated. in classes, Defined variables are called domains for classes themselves. It can be public, private, and so on. The attribute is a feature of the class visible externally and is a feature that the class shows to external users. As we mentioned above, the domain can be public, but declaring the domain as public is not conducive to class encapsulation, because external users can directly modify the class. So we can use attributes. We only disclose their attributes. As for how to assign values (set) to them, how to perform values (get) has been encapsulated, the class is invisible to the outside. For external users, they can only use it, but cannot control it. How to Control Operations is determined by the class itself. Do you understand?