C# syntax with generics
I have a question about following variable declaration. What does that mean?
List<string>.Enumerator enumerator
List is a generic type, where string serves 开发者_JAVA百科as a type parameter. How to interpret the .Enumerator after that?
List<T>
has a nested class in it, called Enumerator
.
So the type definition of that is List<T>.Enumerator
(and in your case T
is a string
).
P.S.
Actually, List<T>.Enumerator
is a struct
, not a class
, anyway the type definition would be the same.
In fact for all nested types it's always OuterType.NestedType
Try this link, has all information about List.Enumerator: Enumerator at MSDN documentation
In essens the enumerator is used while looping over the list with for each: "Initially, the enumerator is positioned before the first element in the collection. At this position, Current is undefined. Therefore, you must call MoveNext to advance the enumerator to the first element of the collection before reading the value of Current."
精彩评论