Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the runtime shows the generic types as "GenericType`n"?

And why doesn't it shows the real type (eg: List<string> instead of List`1)?
Where does this strange (to me) notation comes from?

like image 398
remio Avatar asked Sep 26 '09 20:09

remio


2 Answers

The CLR name for generic List<T> with one type parameter is

System.Collections.Generic.List`1

List<T> is the C# style of naming that type.

The notation is a convention defined to give you the ability to overload generic types by parameter count. If you declare a class named List with two type parameters (e.g. List<T,U>) the compiler would be able to choose the right one. It'll be named:

System.Collections.Generic.List`2

and a non-generic List class will be named:

System.Collections.Generic.List

Note that the CLR does not require generic types to be named like that. It's just a convention for the compilers to be able to pick the right type.

like image 74
mmx Avatar answered Oct 19 '22 12:10

mmx


It doesn't show List<string> because that's C# dependent syntax. A List in .Net source code could be declared as List<string>, List(Of String) or any of the other 60 or so languages/syntaxes that can compile down to MSIL.

So what you're seeing is the more generic MSIL syntax.

The `1 means that it is a List that has one generic parameter.

like image 22
womp Avatar answered Oct 19 '22 13:10

womp