C # key knowledge detailed (3)

zhaozj2021-02-08  286

Guide: A certain inspector for using the RAD development tool is very familiar, programmers can operate the Publish keywords in Delphi by it can operate the object properties. Access the Private member by accessing the flag, there are two ways to reveal the naming properties of the class in C #, through the domain member or by attribute.

Author: wkrain www.ASPCool.com

Chapter 3: Class Attributes

A certain inspector using the RAD development tool is very familiar, the programmer introduces the Publish keyword in Delphi to publish the general welcome of the object properties by it can operate the object attribute. Access the Private member by accessing the flag, there are two ways to reveal the naming properties of the class in C #, through the domain member or by attribute. 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 SET / GET

Please see example:

Using system;

Public Class Test

{

Private int m_nwrite;

Private int ready 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

{

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, myteest.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-2327.html

New Post(0)