There are a lot of problems for xiaoxin. Well, there are still such problems today! Code As follows:
Public Class Demo
{
Public Static T show < T > (T)
{
Return A;
}
Public Static Void Get ()
{
Int Myint = Show < Int > ( 2 );
}
}
In this Code, "T" after "static" indicates the expected data type. "T" in "show (t)" indicates the data type to be input. You can see it through the "get" method. Int Myint = show < Int > ( 2 );
This Int Is the type you want to enter. Here, the int can be replaced with the type you want at will ,. Public StaticT show<T>(T) The T type of the parameter section is the same as that of the show front side! Not necessarily only put one parameter. In theory, N or more parameters can be put. In this way, you can choose any parameter. Also, you can pass in multiple data type parameters. For example:
Public Class Demo
{
Public Static T show < T, x, y > (T a, x B, Y C)
{
Return A;
}
Public Static Void Get ()
{
Int Myint = Show < Int , String , Double > ( 2 , " ABC " , 4.0 );
}
}
when you first arrive, if an error occurs, please criticize and correct it! thank you for your guidance from Mr. Hao. Haha! next time! bye!