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(); } } }
C#属性
最新推荐文章于 2024-11-04 23:44:57 发布