using System;
using System.Collections.Generic;
using System.Text;
namespace Properties
{
public class PropertyHolder
{
private int someProperty = 0;
public int SomeProperty//属性名的首字母必须大写,这是属性名SomeProperty和域名someProperty的惟一区别。
{
get
{
return someProperty;
}
set
{
someProperty = value;
}
}
}
class Program
{
static void Main(string[] args)
{
PropertyHolder propHold = new PropertyHolder();
propHold.SomeProperty = 5;
Console.WriteLine("Property Value:{0}", propHold.SomeProperty);
Console.ReadKey();
}
}
}
Properties(C#)
最新推荐文章于 2024-11-04 23:44:57 发布
本文介绍了一个简单的 C# 程序示例,展示了如何定义一个包含属性的类,并通过 Main 方法实例化该类及调用其属性。通过此示例,读者可以了解 C# 中属性的基本用法及其在类中的实现方式。
757

被折叠的 条评论
为什么被折叠?



