PageRenderTime 27ms CodeModel.GetById 25ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

/Test/interface_properties.cs

http://github.com/fishman/ctags
C# | 64 lines | 56 code | 3 blank | 5 comment | 0 complexity | e483220244ce91c68866aa865bc9d89f MD5 | raw file
Possible License(s): GPL-2.0
 1// cs_interface_properties.cs
 2// Interface Properties
 3using System;
 4interface IEmployee 
 5{
 6   string Name 
 7   {
 8      get;
 9      set;
10   }
11
12   int Counter 
13   {
14      get;
15   }
16}
17
18public class Employee: IEmployee 
19{
20   public static int numberOfEmployees;
21   private int counter;
22   private string name;
23   // Read-write instance property:
24   public string Name 
25   {
26      get 
27      {
28         return name; 
29      }
30      set 
31      {
32         name = value; 
33      }
34   }
35   // Read-only instance property:
36   public int Counter 
37   {
38      get 
39      {
40         return counter; 
41      }
42   }
43   // Constructor:
44   public Employee() 
45   {
46      counter = ++counter + numberOfEmployees;
47   }
48}
49
50public class MainClass 
51{
52   public static void Main() 
53   {
54      Console.Write("Enter number of employees: ");
55      string s = Console.ReadLine();
56      Employee.numberOfEmployees = int.Parse(s);
57      Employee e1 = new Employee();
58      Console.Write("Enter the name of the new employee: ");
59      e1.Name = Console.ReadLine();  
60      Console.WriteLine("The employee information:");
61      Console.WriteLine("Employee number: {0}", e1.Counter);
62      Console.WriteLine("Employee name: {0}", e1.Name);
63   }
64}