Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C# class properties

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to use C# attributes". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

C # class properties

Some inspector who have used RAD development tools are very familiar with it. Programmers can manipulate object properties through it. PUBLISH keyword is introduced into DELPHI to publish object properties. To access private members through access flags, there are two ways to reveal the named properties of a class in c #-either through domain members or through attributes. The former is implemented as a member variable with public accessibility; the latter does not respond directly to the storage location, but is accessed through the access flag (accessors). When you want to read or write the value of an attribute, the access flag qualifies the statement to be implemented. The access flag used to read the value of the attribute is marked as the keyword get, while the reader-writer flag for the value of the property to be modified is marked as set.

C# class properties include

◆ can only read get

◆ can only write set

◆ readable and writable set/get

Take a look at the example:

Using System; public class Test {private int masked nWrite100; private int masked nWriteRead; public int WRITEREAD {get {return masked nWriteRead;} set {set {m_nWrite = value;}} public int READ {get {Test MyTest = new Test;}} class TestApp {public static void Main () {Test MyTest = new Test (); int iRead MyTest.READ; / / get MyTest.WRITE=250 / / set MyTest.WRITEREAD+=10000000; / / set and get Console.WriteLine ("get: {0} set: {1} set/get: {2}", iMagneMyTest.WRITE ·MyTest.WRITEREAD);}} the content of "how to use C# class properties" ends here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report