c # Attribute 1 (Property)

Create a read-only property

the using the System;
 the using the System.Collections;
 the using the System.Collections.Generic;
 the using the System.Globalization;
 the using the System.Linq;
 the using the System.Text;
 the using coding exercise; 

namespace encoding exercise 
{ 
    // create classes people, there are two attributes 
    public  class the Employee 
    { 
        public  static  int NumberOfEmployees;
         Private  static  int counter;
         Private  String name; 

        // A Read-Write Property instance: 
        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);
    }
}
}

 

Guess you like

Origin www.cnblogs.com/jestin/p/11535036.html