Created
April 27, 2012 03:33
-
-
Save tnngo2/2505556 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace Theory8 | |
{ | |
class Employee | |
{ | |
private string _empName; | |
private int _empID; | |
public Employee(string name, int num) | |
{ | |
_empID = num; | |
_empName = name; | |
} | |
public string Name | |
{ | |
get { return _empName; } | |
} | |
public int Id { get { return _empID; } } | |
} | |
class GenericList<T> where T: Employee | |
{ | |
T[] _name = new T[3]; | |
private int _counter = 0; | |
public void Add(T val) | |
{ | |
_name[_counter] = val; | |
_counter++; | |
} | |
public void Display() | |
{ | |
for (int i = 0; i < _counter; i++) | |
{ | |
Console.WriteLine(_name[i].Name + ", " + _name[i].Id); | |
} | |
} | |
} | |
class ClassConstraintDemo | |
{ | |
static void Main(string[] args) | |
{ | |
GenericList<Employee> objList = new GenericList<Employee>(); | |
objList.Add(new Employee("John",100)); | |
objList.Add(new Employee("James", 200)); | |
objList.Add(new Employee("Patrich", 300)); | |
objList.Display(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment