Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 887
Peter17 Avatar asked Jan 20 '23 08:01

Peter17


2 Answers

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

like image 110
digEmAll Avatar answered Jan 22 '23 21:01

digEmAll


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

like image 44
Avada Kedavra Avatar answered Jan 22 '23 20:01

Avada Kedavra