C # key knowledge detailed (3)

zhaozj2021-02-11  190

Chapter III: Class Attributes Use the INSPECTOR for the RAD Development Tool, which is very familiar, programmers can operate the Publish keywords in Delphi to publish the general welcome of the programmer by the programmer. Access the Private member, there are two ways to discover the naming properties of the class in C #, through domain members or through properties. The former is implemented as a member variable with public access; the latter does not respond directly to the storage location, just accessible by access logo (Accessors). When you want to read or write the value of the property, the access flag limits the statement implemented. The access flag for reading the value of the attribute is a keyword GET, and the read and write error flag to modify the value of the property is SET.

Class properties

Can only read GET can only write SET readable to write SET / GET

Please see example:

Using system; public class test {private int nnwrite; private int ready m_nread = 100; private int m_nwriterad;

Public int WriteRead {get {return m_nwriteread;} ​​set {m_nwriteread = value;}}

Public int Write {set {m_nwrite = value;}}

Public int {get {return m_nread;}}

}

Class testapp {public static void main () {test mytest = new test (); int i = mytest.read; // get mytest.write = 250; // set mytest.writeRead = 10000000; // set and get

Console.writeline ("Get: {0} set: {1} set / get: {2}", i, mytest.write, mytest.writeread;}}

If you want to hide the details of the class internal storage structure, you should use the access flag. Access flag passes a new value in the attribute in the value parameter. At the same time, you can get the opportunity to achieve effective code in the SET flag.

转载请注明原文地址:https://www.9cbs.com/read-4495.html

New Post(0)