G
Guest
Make a template of a template:
public class A<T>
{
A(string s){}
}
public class D<Tobject, Tclass> :
where Tobject : Object
where Tclass : A<Tclass>
{
public Tobject someFunction()
{
Tclass c = new Tclass("Test"); // Compiler error: Tclass doesn't have new
constraint
return null; // Compiler error: Tobject is not nullable
}
}
How do I let the compiler know that Tobject is nullable?
How do I let it know that since Tclass is constrained to types of A it must
implement the new operator with string argument?
public class A<T>
{
A(string s){}
}
public class D<Tobject, Tclass> :
where Tobject : Object
where Tclass : A<Tclass>
{
public Tobject someFunction()
{
Tclass c = new Tclass("Test"); // Compiler error: Tclass doesn't have new
constraint
return null; // Compiler error: Tobject is not nullable
}
}
How do I let the compiler know that Tobject is nullable?
How do I let it know that since Tclass is constrained to types of A it must
implement the new operator with string argument?