When will the. NET 2.0 generic be built (construct )? When does the compiler know generic type parameters? Consider the following quiz:
Quiz 1: Write the followingCodeOutput
Class Program ... { Static Void Main ( String [] ARGs) ... {<Int>A= NewA<Int>(); A. internalcall (12);} } Class A < T > ... { Public Void Internalcall (t obj) ... {Test (OBJ );} Public Void Test < U > (U obj) ... {Console. writeline ("U");} Public Void Test ( Int OBJ) ... {Console. writeline ("Int");} }
Which overload will be called? Only from the class, it seems that there is only one choice; but from the caller's perspective, there are two choices ......
Quiz 2: Write the output of the following code
Class Program ... { Static Void Main ( String [] ARGs) ... {<Int>A= NewA<Int>(); A. Test (12);} } Class A < T > ... { Public Void Test (t obj) ... {Console. writeline ("T");} Public Void Test ( Int OBJ) ... {Console. writeline ("Int");} }
Well ...... This is the most strange example. When you enter the code, IDE will tell you that there are two identical overload functions. Which one will you call?
Quiz 3: Write the output of the following code
Class Program ... { Static Void Main ( String [] ARGs) ... {<Int>A= NewA<Int>(); A. Test (12); A. Test (12.0);} } Class A < T > ... { Public Void Test < U > (U obj) ... {Console. writeline ("U");} Public Void Test (t obj) ... {Console. writeline ("T");} }
After you have made these questions, you can think of the features that can be used to compileProgram?
2005.11.08 from: csdn DOTNET blog Expert Group ninputer