c#属性1(Property)

4010 ワード

読み取り専用アトリビュートを作成するには
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);
    }
}
}