Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use C# class properties

Shulou Source: shulou.com Published: 2022-06-02 09:07:53 09月21日 Update

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!

Tags: Attributes flags caches access members keywords keywords content objects more knowledge programs programmers utility learning and then locations examples variables just Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft Docker Huawei Shulou Technology