Okay, let's get frustrated first, and then start this post.
I finally pulled Whidbey Alpha from eMule yesterday, GB. After installing it today, I can't wait to try the generic type in C #. However, I want to cry! This function is too weak. How long will it take? There will be no new things to play with the C # generic model. This is for me to switch from C ++ to C, where can this be called generic !! In addition to creating a container (call! It is useless even if it is a container. When I first saw the generic constraint on msdn, I felt bad. It is said that the CLR supports generics, but the actual implementation of things, the function is not necessarily better than Java (the efficiency is C # generics is much higher, I will try again next time ). The most exaggerated is that the instantiated type must have a non-argument constructor!
Sigh... Bruce Eckel's words are really pertinent.
I am so sad that I can't write any more. First, I will test my first C # Generic Model.ProgramPost it out. I will write a detailed article about take a close look at C # generics.
Using system;
Namespace consoleapplication1
{
InterfaceItest
{
Void testmethod ();
}
Class Testtype : Itest
{
// Public testtype (int I ){}
Public void testmethod ()
{
Console . Writeline ("testing ");
}
}
ClassTest <T> where T: Itest , New ()
{
Public test (int I)
{
Datat = new T ();
Dataint = I;
}
Public void Foo ()
{
Datat. testmethod ();
}
Public t datat
{
Get {return datat ;}
}
Public int dataint
{
Get {return dataint ;}
}
Private t datat;
Private int dataint;
}
Class Class1
{
[ Stathread ]
Static void main (string [] ARGs)
{
Test < Testtype > Ti = new Test < Testtype > (4 );
// Console. writeline (TI. datat );
Ti. Foo ();
Console . Writeline (TI. dataint );
}
}
}