创建一个只读属性

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