Skip to content

Instantly share code, notes, and snippets.

@tnngo2
Created April 27, 2012 08:35
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/2507482 to your computer and use it in GitHub Desktop.
Save tnngo2/2507482 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Theory8_1
{
interface IDetails
{
void GetDetails();
}
class Student: IDetails
{
private string _studName;
private int _studID;
public Student(string name, int num)
{
_studID = num;
_studName = name;
}
public void GetDetails()
{
Console.WriteLine(_studID + "\t" + _studName);
}
}
class GenericList<T> where T:IDetails
{
T[] _value = new T[3];
private int _counter = 0;
public void Add(T val)
{
_value[_counter] = val;
_counter++;
}
public void Display()
{
for (int i = 0; i < 3; i++)
{
_value[i].GetDetails();
}
}
}
class InterfaceConstraintDemo
{
static void Main(string[] args)
{
GenericList<Student> objList = new GenericList<Student>();
objList.Add(new Student("Wilson", 120));
objList.Add(new Student("Jack", 130));
objList.Add(new Student("Peter", 140));
objList.Display();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment