Chapter 3: class attributes
Certain inspector who have used RAD development tools are familiar with it. programmers can use it to operate on Object Attributes. The PUBLISH keyword is introduced in DELPHI to PUBLISH object attributes, which is widely welcomed by programmers. access a private member through an access flag. in c #, there are two ways to reveal the class's naming attributes-either through a domain member or through an attribute. The former is implemented as a member variable with public access; the latter does not directly respond to the storage location, but is only accessed through the accessors. When you want to read or write the attribute value, the access flag limits the implemented statement. The access Mark used to read the attribute value is recorded as the keyword get, and the read/write mark used to modify the attribute value is recorded as set.
Class attributes
Read Only get
Only set can be written.
Readable and writable set/get
See the example below:
Using System;
Public class Test
{
Private int m_nWrite;
Private int readonly m_nRead = 100;
Private int m_nWriteRead;
Public int WRITEREAD
{
Get {return m_nWriteRead ;}
Set {m_nWriteRead = value ;}
}
Public int WRITE
{
Set {m_nWrite = value ;}
}
Public int READ
{
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's internal storage structure, you should use an access flag. The access flag transmits a new value to the attribute in the value parameter. At the same time, you can get the opportunity to add valid code in the set flag.