C # attributes and fields in the class

Source: Internet
Author: User

Fields are custom variables or constants in the class. They are used to record related information and attributes of the class. They are usually no different from external definitions, that is, they need to add public modifiers;

 

Attribute is also one of the concepts in the class, that is, a function method for external access to internal private fields,

 

It is generally divided into custom attributes:

Use the get and set accessors to assign values to fields.

Default definition,

Attribute fields are generated by default if only get and set are declared and not specified.

Note that read-only and write-only attributes can be implemented by defining only one of get and set attributes;

 

Attribute can also be set to restrict access to fields. For example, you can add judgment in set, and other values can be returned in get return.

 

Static fields can be implemented through static attributes, which can be directly used in the class, and can be accessed outside the class by class name. Attribute (provided that the attribute must be public );

 

C # attributes and fields in the class

Related Article

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.