using System;
class MyBase {
public void hello() {
Console.WriteLine("Hello");
}
}
class B : MyBase { }
class C { }
class Test where T : MyBase {
T obj;
public Test(T o) {
obj = o;
}
public void sayHello() {
obj.hello();
}
}
class BaseClassConstraintDemo {
public static void Main() {
MyBase a = new MyBase();
B b = new B();
C c = new C();
Test t1 = new Test(a);
t1.sayHello();
Test t2 = new Test(b);
t2.sayHello();
// The following is invalid because
// C does not inherit MyBase.
// Test t3 = new Test(c); // Error!
}
}