interface IEmployee
{
string Name
{
get;
set;
}
int Counter
}
public class Employee : IEmployee
public static int numberOfEmployees;
private string name;
public string Name // read-write instance property
get
{
return name;
}
set
name = value;
private int counter;
public int Counter // read-only instance property
return counter;
public Employee() // constructor
counter = ++counter + numberOfEmployees;
class TestEmployee
static void Main()
System.Console.Write("Enter number of employees: ");
Employee.numberOfEmployees = int.Parse(System.Console.ReadLine());
Employee e1 = new Employee();
System.Console.Write("Enter the name of the new employee: ");
e1.Name = System.Console.ReadLine();
System.Console.WriteLine("The employee information:");
System.Console.WriteLine("Employee number: {0}", e1.Counter);
System.Console.WriteLine("Employee name: {0}", e1.Name);
System.Console.ReadLine();
輸入:
<code>Enter number of employees: 210</code>
<code>Enter the name of the new employee: Hazem Abolrous</code>
<code>The employee information:</code>
<code>Employee number: 211</code>
<code>Employee name: Hazem Abolrous 本文轉自yonghu86 51CTO部落格,原文連結:http://blog.51cto.com/yonghu/1321454,如需轉載請自行聯系原作者</code>