ArraySegment<T>.Enumerator 结构

定义

ArraySegment<T> 的元素提供枚举器。Provides an enumerator for the elements of an ArraySegment<T>.

public: value class ArraySegment<T>::Enumerator : System::Collections::Generic::IEnumerator<T>
public struct ArraySegment<T>.Enumerator : System.Collections.Generic.IEnumerator<T>
type ArraySegment<'T>.Enumerator = struct
    interface IEnumerator<'T>
    interface IEnumerator
    interface IDisposable
Public Structure ArraySegment(Of T).Enumerator
Implements IEnumerator(Of T)

类型参数

T
继承
ArraySegment<T>.Enumerator
实现

注解

语言的foreach和 For Each ... C# C# Visual Basic 中的下一个构造隐藏了枚举器的复杂性。The C# foreach of the C# language and the For Each...Next construct in Visual Basic hides the complexity of enumerators. 建议使用 foreachFor Each...Next,而不是直接操作枚举器。Instead of directly manipulating the enumerator, using foreach or For Each...Next is recommended.

最初,枚举器定位在 ArraySegment<T>中第一个元素之前。Initially, the enumerator is positioned before the first element in the ArraySegment<T>. 在此位置上,未定义 CurrentAt this position, Current is undefined. 在读取 Current的值之前,必须调用 MoveNext 以将枚举数前移到 ArraySegment<T> 中的第一项。You must call MoveNext to advance the enumerator to the first item in the ArraySegment<T> before reading the value of Current.

Current 在调用 MoveNext 之前返回相同的值。Current returns the same value until MoveNext is called. MoveNextCurrent 设置到 ArraySegment<T>中的下一项。MoveNext sets Current to the next item in the ArraySegment<T>.

如果 MoveNext 越过 ArraySegment<T>的末尾,MoveNext 将返回 falseIf MoveNext passes the end of the ArraySegment<T>, MoveNext returns false. 当枚举器处于此状态时,对 MoveNext 的后续调用也将返回 false 并且 Current 未定义。When the enumerator is at this state, subsequent calls to MoveNext also return false and Current is undefined. 不能再次将 Current 设置到 ArraySegment<T> 中的第一项;必须改为创建新的枚举器实例。You cannot set Current to the first item in the ArraySegment<T> again; you must create a new enumerator instance instead.

属性

Current

获取对枚举器当前位置的项目的引用。Gets a reference to the item at the current position of the enumerator.

方法

Dispose()

释放此枚举器实例使用的所有资源。Releases all resources used by this enumerator instance.

MoveNext()

使枚举数前进到 ArraySegment<T> 的下一个元素。Advances the enumerator to the next element of the ArraySegment<T>.

显式界面实现

IEnumerator.Current

获取枚举数当前位置的元素。Gets the element at the current position of the enumerator.

IEnumerator.Reset()

将枚举器设置为其初始位置,该位置位于数组段中第一个元素之前。Sets the enumerator to its initial position, which is before the first element in the array segment.

适用于