C # Example 6 (Chapter 6)

Source: Internet
Author: User

Store user numbers and names using properties

Private string id = ""; // defines a variable of the string type, which is used to record the user's number private string name = ""; // defines a variable of the string type, used to record the user name // <summary> // defines the user ID attribute, this attribute is a readable and writable property // </Summary> Public String ID {get {return ID;} set {id = value ;}} /// <summary> /// define the user name attribute. The attribute is a readable and writable attribute. /// </Summary> Public string name {get {return name ;} set {name = value ;}} private void form=load (Object sender, eventargs e) {id = "bh001"; // assign name = "MR1" to the user ID attribute "; // assign lab_first.text = ID + "" + name to the user name attribute; // display the user ID and user name ID = "bh002 "; // rename the user ID attribute with name = "MR2"; // rename the user name attribute with lab_second.text = ID + "" + name; // Display User ID and user name }}

Attribute is the abstraction of real entity features. It provides access to the class or object nature. The tired attribute describes the status information. In the case of a class, the attribute value indicates the State value of the object. It does not rely on storage devices, but on accessors. These accessors specify the statements to be executed when their values are read or written. Therefore, attributes provide a mechanism to associate certain features of reading and writing objects with some operations, so that programmers can use attributes like common members.

 

C # Example 6 (Chapter 6)

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.