See the following routine:
Using system;
Namespace consoleapplication1
{
InterfaceItest
{
Void testmethod ();
}
Class Testtype : Itest
{
// Public testtype (int I ){}
Public void testmethod ()
{
Console . Writeline ("testing ");
}
}
Class Test
{
Public static void Foo <t> (T)
Where t: Itest
{
T. testmethod ();
}
}
Class Class1
{
[ Stathread ]
Static void main (string [] ARGs)
{
Object o = newTesttype ();
Test . Foo (O ); // Compile-Error
}
}
}
Note that the actual type of the O object is testtype, which inherits the itest interface, but still reports an error during compilation. That is to say, the check on whether an object meets constraints is completed during the compilation period and does not involve the type information during the runtime. That is to say, in C #, the generic instantiation check is the same as in C ++, and is completed during the compilation period.
As a result, the null syntax like constraints does not bring any benefits at all, and the advantages of the generic itself are also castrated. I really cannot think of the purpose of doing so.