问题
What is the meaning of 1
after IEnumerable in: System.Collections.Generic.IEnumerable`1
回答1:
It is the generic arity of the type, or put another way, the number of type parameters a generic type supports. IEnumerable<T>
supports a single type parameter. If you were to look at Dictionary<TKey, TValue>
you would notice an arity value of 2.
回答2:
Within the .NET type system, it is necessary that types have unique names. Although it is only possible to create instances of bound generic types (e.g. IEnumerable<System.Int32>
or IEnumerable<System.String>
), the unbound generic type may be used in certain contexts. Within the language C#, such type would be written as IEnumerable<>
but within the type system it is notated as IEnumerable~1
[~ used to avoid format problems]. Note that the name of the bound generic type starts with the name of the unbound type, so if the unbound generic were called IEnumerable<>
within the type system, the name of the bound generic would have to start with IEnumerable<>
, including the back-to-back less-than-greater-than signs.
来源:https://stackoverflow.com/questions/16768208/in-c-sharp-what-is-the-meaning-of-1-after-ienumerable-in-system-collections-gene