HashSet<T>.Enumerator.IEnumerator.Current 屬性

定義

取得位於目前列舉值位置的項目。Gets the element at the current position of the enumerator.

property System::Object ^ System::Collections::IEnumerator::Current { System::Object ^ get(); };
object System.Collections.IEnumerator.Current { get; }
object? System.Collections.IEnumerator.Current { get; }
member this.System.Collections.IEnumerator.Current : obj
 ReadOnly Property Current As Object Implements IEnumerator.Current

屬性值

Object

位於集合中列舉值目前位置的項目,做為 ObjectThe 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.

備註

IEnumerator.Current在下列任一情況下都未定義:IEnumerator.Current is undefined under any of the following conditions:

  • 枚舉器位於集合的第一個元素之前。The enumerator is positioned before the first element of the collection. 這會在建立枚舉器之後,或在 IEnumerator.Reset 呼叫方法之後發生。That happens after an enumerator is created or after the IEnumerator.Reset method is called. MoveNext 必須呼叫方法,將列舉值前移至集合的第一個元素,然後再讀取屬性的值 IEnumerator.CurrentThe MoveNext method must be called to advance the enumerator to the first element of the collection before reading the value of the IEnumerator.Current property.

  • 最後一個呼叫會 MoveNext 傳回 false ,這表示集合的結尾,而枚舉器位於集合的最後一個元素之後。The last call to MoveNext returned false, which indicates the end of the collection and that the enumerator is positioned after the last element of the collection.

  • 因為集合中所做的變更,例如新增、修改或刪除元素,所以列舉值會無效。The enumerator is invalidated due to changes made in the collection, such as adding, modifying, or deleting elements.

IEnumerator.Current不會移動列舉值的位置,而連續的呼叫會傳回 IEnumerator.Current 相同的物件,直到 MoveNext 呼叫或為止 IEnumerator.ResetIEnumerator.Current does not move the position of the enumerator, and consecutive calls to IEnumerator.Current return the same object until either MoveNext or IEnumerator.Reset is called.

適用於