I have seen a lot of generic descriptions written by netizens, and many of them are illustrated by examples. It is a bit dizzy.
Later, I checked the video tutorial to understand the generic type.
The concepts of other generic types are not complex, but they are completed using real-time compilation.
A generic type is defined here.
Public class betterclass <t>
{
Private t obj1;
Public betterclass ()
{
}
}
For example, betterclass = new betterclass <string>;
When this sentence is compiled instantlyCodeWill build a new class in the memory.
Public class betterclass <string>
{
Private string obj1;
Public betterclass ()
{
}
}
For example, betterclass = new betterclass <int>;
When this code is compiled in real time, a new class will be built in the memory.
Public class betterclass <int>
{
Private string int;
Public betterclass ()
{
}
}
Note: The same type is only constructed once in the memory.
TIt is just a 'placeholder '. during real-time compilation, it is replaced with the class instance specified during instantiation.
It's much easier to understand and learn other usage.