Junior — Middle
Can you list and describe the methods implemented in the IEnumerator interface?
sobes.tech AI
Answer from AI
The IEnumerator interface in C# defines methods for iterating over a collection. Main methods and properties:
bool MoveNext()— moves the pointer to the next element of the collection. Returnstrueif the next element exists, otherwisefalse.object Current { get; }— property that returns the current element of the collection.void Reset()— resets the enumerator to its initial position, before the first element of the collection.
Example of usage:
IEnumerator enumerator = collection.GetEnumerator();
while (enumerator.MoveNext())
{
var item = enumerator.Current;
// process item
}