IEnumerator<T>.Current Property


取得集合中位於列舉值目前位置的元素。Gets the element in the collection at the current position of the enumerator.

 property T Current { T get(); };
public T Current { get; }
member this.Current : 'T
Public ReadOnly Property Current As T

Property Value


位於列舉值中目前位置的集合中的元素。The element in the collection at the current position of the enumerator.


在下列任一情況下,Current 未定義: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. 在讀取 Current的值之前,必須呼叫 MoveNext,將枚舉器前移至集合的第一個元素。MoveNext must be called to advance the enumerator to the first element of the collection before reading the value of Current.

  • 最後一次呼叫 MoveNext 傳回 false,表示集合的結尾。The last call to 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.

Current 會傳回相同的物件直到呼叫 MoveNextCurrent returns the same object until MoveNext is called. MoveNext 會將 Current 設定為下一個項目。MoveNext sets Current to the next element.

Notes to Implementers

若要執行此介面,必須實作為泛型 IEnumerator 介面。Implementing this interface requires implementing the nongeneric IEnumerator interface. [Current] 屬性會出現在兩個介面上,且具有不同的傳回型別。The Current property appears on both interfaces, and has different return types. 將非泛型 Current 屬性實作為明確的介面執行。Implement the nongeneric Current property as an explicit interface implementation. 這可讓非泛型介面的任何取用者使用泛型介面。This allows any consumer of the nongeneric interface to consume the generic interface.

Applies to

See also