MSDN Library

HashSet<T>.Enumerator.IEnumerator.Current Property

Gets the element at the current position of the enumerator.

Namespace:  System.Collections.Generic
Assemblies:   System.Collections (in System.Collections.dll)
  System.Core (in System.Core.dll)

Object IEnumerator.Current { get; }

Property Value

Type: System.Object
The element in the collection at the current position of the enumerator, as an Object.




The enumerator is positioned before the first element of the collection or after the last element.

After an enumerator is created or after the Reset method is called, the MoveNext method must be called to advance the enumerator to the first element of the collection before reading the value of the Current property; otherwise, Current is undefined.

Current also throws an exception if the last call to MoveNext returned false, which indicates the end of the collection.

Current does not move the position of the enumerator, and consecutive calls to Current return the same object until either MoveNext or Reset is called.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and the next call to MoveNext or Reset throws an InvalidOperationException. If the collection is modified between calling MoveNext method and obtaining the value of the Current property, Current returns the element that it is set to, even if the enumerator is already invalidated.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
© 2015 Microsoft