Properties in C#

Properties in C# The public account “DotNet Learning Exchange” shares the details of learning DotNet. This article briefly introduces properties in C#. The public account “DotNet Learning Exchange” shares the details of learning DotNet. Introduction A property is a member that represents an instance of a class or a data item in a class. Using properties looks very much like writing or To read a field, the syntax is the same. The following code shows the use of a class named D. It has a public field and a public property. From the usage Can’t tell them apart. D d = new D();​d.MyField = 7; //Assign a value to the fieldd.MyProperty = 10; //Assign a value to the attributeConsole.WriteLine($”{d.MyField} {d.MyProperty}”); //Read fields and attributes Similar to fields, attributes have the following characteristics: 1. It is a named class member. 2. It has types. 3. It can be assigned and read. Unlike fields, attributes are A function member. 1. It does not allocate memory for data storage. 2. It executes code. A simple example about attributes The code is as follows: public class Person{ private string name; // Private field​ public string Name {              …

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索