System.Collections.Generic.IEnumerator<T>.Current Property

Gets the element in the collection at the current position of the enumerator.

Syntax

public T Current { get; }

Value

The element in the collection over which the current instance is positioned.

Exceptions

TypeReason
An unspecified exception type

If IEnumerator.MoveNext is not called before the first call to IEnumerator<T>.Current.

-or-

If the previous call to IEnumerator.MoveNext returned false , indicating the end of the collection.

Remarks

IEnumerator`1.Current is undefined under any of the following conditions:

  • The enumerator is positioned before the first element in the collection, immediately after the enumerator is created. IEnumerator.MoveNext must be called to advance the enumerator to the first element of the collection before reading the value of IEnumerator`1.Current.

  • The last call to IEnumerator.MoveNext returned false, which indicates the end of the collection.

  • The enumerator is invalidated due to changes made in the collection, such as adding, modifying, or deleting elements.

IEnumerator`1.Current returns the same object until IEnumerator.MoveNext is called. IEnumerator.MoveNext sets IEnumerator`1.Current to the next element.

Requirements

Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0