The meaning of Dictionary`2 in a stack trace

The System.Collections.Generic.Dictionary`2 means that the type is System.Collections.Generic.Dictionary, with two type arguments. So in this case it means that the type is System.Collections.Generic.Dictionary<TKey, TValue>, as we all know it.


This's the way .Net makes classes' names. The initial declaration

 Dictionary<K, V>

will be turned into Dictionary'2 type name where '2 means two generic parameters:

 // Dictionary`2 - two generic parameters
 Console.WriteLine(typeof(Dictionary<int, string>).Name);

 // List`1 - one generic parameter
 Console.WriteLine(typeof(List<int>).Name);

Please compare:

 // IDictionary`2 - two generic parameters
 Console.WriteLine(typeof(IDictionary<int, string>).Name);

 // IDictionary - no generic parameters
 Console.WriteLine(typeof(System.Collections.IDictionary).Name);

Tags:

C#

Stack Trace