Properties in C #

Source: Internet
Author: User

An attribute is an abstraction of an entity feature in the real world that provides access to the nature of a class or object. For example, a user's name, the size of a file, and the title of a window can all be attributes. The property of a class describes the state information, and the value of the property in an instance of the class represents the state value of the object.

The attributes in C # more fully embody the encapsulation of the object: not manipulating the data content of the class directly, but accessing it through the accessor. It uses both get and set to read and write the values of properties, which in C + + is a task that requires the programmer to do it manually.

12.2.1 the C # attribute declaration

The properties of C # are declared in the following manner:

Attributes Proterty-modifiers type Member-name {accessor-declarations}

The modifiers for the attribute property-modifiers are:

New

Public

Protected

Internal

Private

Static

Virtual

Sealed

Override

Abstract

The static,virtual,override and abstract modifiers cannot be used at the same time in the above modifiers.

The access declaration accessor-declaration of a property must be enclosed in a pair of "{" and "}" braces, giving instructions for reading and writing the value of the property.

Although the syntax of a property is similar to that of a field, it cannot be used as a variable, nor can it be passed as a reference parameter or an output parameter.

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.