an attribute is also called an accessor. It is a member like this: they provide a flexible mechanism to read, write, or calculate private field values. Attributes can be used like public data members, but they are actually special methods called "accessors". accessors and methods can be overwritten, this allows data to be easily accessed while providing the security and flexibility of the method.
Attribute enables the class to obtain and set values in a public way, while hiding the implementation or verificationCode. They can verify the data before the change is allowed. They can transparently disclose the data of a class, which is actually retrieved from other sources (such as databases, when data is changed, they can take actions, such as triggering an event or changing the values of other fields.
Only access modifiers, actual data types, attribute names, and empty GET/set scopes are specified. The private returned field and the appropriate get/set implementation logic are automatically generated during compilation, and the private field can only be simply encapsulated. Automatic attributes cannot be read-only or write-only.
Accessors can have the same or different visibility and access levels. If an access modifier is used for the accessors, the accessible domain of the accessors is determined by the modifier. If you do not use an access modifier for the accessors, the accessible domain of the accessors is determined by the Accessibility level of the attributes or indexers.
The attribute that does not implement the set method is read-only.
the attribute of the get method is read-only.
Static attributes must use the keyword static, which is applicable to the entire class instead of the class instance. Static attributes can only be static members of the category. Static attributes can be accessed by class names and cannot be called by instances, this is the same as the static method.
- Keywords
-
- Get: returns the property value.
- Set: used to allocate new values.
- Value: defines the value allocated by the set indexer.
Get _/SET _ method pair
unlike fields, attributes are not classified as variables. Therefore, attributes cannot be passed as ref or out parameters.