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)