IEnumerator<T>.Current 屬性

定義

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

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

屬性值

T

位於列舉值中目前位置的集合中的元素。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. MoveNext在讀取的值Current之前,必須呼叫以將枚舉器前移至集合的第一個元素。MoveNext must be called to advance the enumerator to the first element of the collection before reading the value of Current.

  • 最後一次呼叫MoveNextfalse傳回,指出集合的結尾。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.

給實施者的注意事項

執行此介面必須實作為非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.

適用於

另請參閱