Created
April 27, 2012 08:35
-
-
Save tnngo2/2507482 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_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