简体   繁体   中英

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 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 ).

PS

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."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM