c#属性1(Property)
程序员文章站
2022-07-01 17:02:50
创建一个只读属性 ......
创建一个只读属性
using system; using system.collections; using system.collections.generic; using system.globalization; using system.linq; using system.text; using 编码练习; namespace 编码练习 { //创建类people,里面有两个属性 public class employee { public static int numberofemployees; private static int counter; private string name; // a read-write instance property: public string name { get { return name; } set { name = value; } } // a read-only static property: public static int counter { get { return counter; } } // a constructor: public employee() { // calculate the employee's number: counter = ++numberofemployees; } } } public class serchpeople { public static void main() { employee.numberofemployees = 107; employee e1 = new employee(); e1.name = "cave"; console.writeline(employee.counter); } } }
上一篇: 自己尝试实现的文件上传功能
下一篇: 你知道小米有什么功效和作用吗?