namespace Consolepractice
{
class Program {
public static void Main(string[] args) {
// Use the generic type Demo with an int type parameter.
Demo < int > test1 = new Demo < int > (2);
// Call the Write method.
test1.print();
// Use the generic Demo with a string type parameter.
Demo < string > test2 = new Demo < string > ("soumalya das");
test2.print();
// Use the generic Demo with a float type parameter.
Demo < float > test3 = new Demo < float > (4.5 f);
test3.print();
Console.ReadKey();
}
}
class Demo < T > {
T _value;
public Demo(T t) {
// The field has the same type as the parameter.
this._value = t;
}
public void print() {
Console.WriteLine(this._value);
}
}
}This code snippet is for generic classes in C#.
