Property: CLS in .NET Framework supports two different properties (huh, it is not to think that it is read-only GET and only write set properties), respectively, the scalar attribute and the vector properties, respectively. What does that mean? Scalar properties represent the characteristics of a single class, which allows a basic value such as Int, DateTim, Color, in the C # syntax, the scalar attribute cannot be parameterized (except Visual Basic .NET). Vector properties are what we usually say, it represents a structure, which allows us to use syntax like an array on the class. For their specific usage, MSDN has a more detailed description, I only talk about design scalar properties, one wrong mistake first look at the principle of writing the SET process: Define a read / write or only write attributes, need to consider How to write a SET accessor, how is the most important thing to handle illegal values, one way to throw an exception, indicating that the customer code cannot accept illegal values. In addition, it is wrong in the SET process. For Property SET indicators, there is a simple code as follows
Public class myproperty {private myproperty; public myproperty () {} public int Age {get {{// If the initiator is less than 0, let him equal 0 if (nage <= 0) {nage = 0;} else {nage = value;}}}} Do you think there is a problem with the code? You can use the following code to test myProperty amyproperty = new myproperty (); amyproperty.age = 20; // or other -100MessageBox.show (AmyProperty.Age.Tostring ()); // Also 0. Oh, the above code has a very hidden mistake. The corrected code is as follows: set {if (value <= 0) // is right, it is here! {NAGE = 0;} else {nage = value;}} is like this, but also design static attributes, or virtual properties!