当前位置: 移动技术网 > IT编程>开发语言>.net > c#属性1(Property)

c#属性1(Property)

2019年09月18日  | 移动技术网IT编程  | 我要评论

冰漪最新,大魔神卡农,老兵你要走吉他谱

创建一个只读属性

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);
    }
}
}

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网