Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HashSet<T>::Enumerator::IEnumerator::Current Property

 

Gets the element at the current position of the enumerator.

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

private:
property Object^ Current {
	virtual Object^ get() sealed = IEnumerator::Current::get;
}

Property Value

Type: System::Object^

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

Exception Condition
InvalidOperationException

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.

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 4.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft