IEnumerator<T>.Current 属性


获取集合中位于枚举数当前位置的元素。Gets the element in the collection at the current position of the enumerator.

 property T Current { T get(); };
public T Current { get; }
public T? Current { get; }
member this.Current : 'T
Public ReadOnly Property Current As 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 在读取的值之前,必须调用以将枚举数前移到集合的第一个元素 CurrentMoveNext 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 之前,MoveNext 返回相同的对象。Current returns the same object until MoveNext is called. MoveNextCurrent 设置为下一个元素。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.