. NET attributes

Source: Internet
Author: User

 

    • Attribute

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.

    • Function

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.

    • Automatic attributes

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.

    • Visibility and access

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.

    • Read-only attribute

The attribute that does not implement the set method is read-only.

    • write-only attribute

the attribute of the get method is read-only.

    • Static attributes
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.
    • Underlying ing

Get _/SET _ method pair

    • Comparison with Fields

unlike fields, attributes are not classified as variables. Therefore, attributes cannot be passed as ref or out parameters.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.