using System;
class MyGenericClass<T> {
T ob;
public MyGenericClass(T o) {
ob = o;
}
public T getob() {
return ob;
}
public void showType() {
Console.WriteLine("Type of T is " + typeof(T));
}
}
public class Test {
public static void Main() {
MyGenericClass<int> iOb;
iOb = new MyGenericClass<int>(102);
iOb.showType();
int v = iOb.getob();
Console.WriteLine("value: " + v);
MyGenericClass<string> strOb = new MyGenericClass<string>("Generics add power.");
strOb.showType();
string str = strOb.getob();
Console.WriteLine("value: " + str);
}
}
|