Skip to content

Instantly share code, notes, and snippets.

@tnngo2
Created April 27, 2012 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnngo2/2505556 to your computer and use it in GitHub Desktop.
Save tnngo2/2505556 to your computer and use it in GitHub Desktop.
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