Default Constructor Constraint
using System;
public class Test{
public static void Main(){
Z obj=new Z();
obj.MethodA<X>();
}
}
public class Z {
public void MethodA<T>() where T:X, new() {
Console.WriteLine("Z.MethodA");
T obj=new T();
obj.MethodB();
}
}
public class X{
public void MethodB() {
Console.WriteLine("X.MethodB");
}
}
Related examples in the same category