ReadOnlySpan<T>.Enumerator ReadOnlySpan<T>.Enumerator ReadOnlySpan<T>.Enumerator ReadOnlySpan<T>.Enumerator Struct

定義

提供 ReadOnlySpan<T> 項目的列舉值。Provides an enumerator for the elements of a ReadOnlySpan<T>.

public: value class ReadOnlySpan<T>::Enumerator
public struct ReadOnlySpan<T>.Enumerator
type ReadOnlySpan<'T>.Enumerator = struct
Public Structure ReadOnlySpan(Of T).Enumerator

類型參數

T
繼承
ReadOnlySpan<T>.EnumeratorReadOnlySpan<T>.EnumeratorReadOnlySpan<T>.EnumeratorReadOnlySpan<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.

一開始,列舉值會放置在中ReadOnlySpan<T>的第一個專案之前。Initially, the enumerator is positioned before the first element in the ReadOnlySpan<T>. 在這個位置上,Current 並未定義。At this position, Current is undefined. 在讀取的MoveNext值之前,ReadOnlySpan<T>您必須呼叫,將枚舉器前移至中的第一個專案CurrentYou must call MoveNext to advance the enumerator to the first item in the ReadOnlySpan<T> before reading the value of Current.

Current會傳回相同的值MoveNext ,直到呼叫為止。Current returns the same value until MoveNext is called. MoveNextCurrent設定為ReadOnlySpan<T>中的下一個專案。MoveNext sets Current to the next item in the ReadOnlySpan<T>.

如果MoveNext傳遞的結尾ReadOnlySpan<T> MoveNextfalse則會傳回。If MoveNext passes the end of the ReadOnlySpan<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 ReadOnlySpan<T>再次設定為中的第一個專案; 您必須改為建立新的列舉值實例。You cannot set Current to the first item in the ReadOnlySpan<T> again; you must create a new enumerator instance instead.

雖然是配置在堆疊上,但指向的ReadOnlySpan<T>基礎資料可能不是。 ReadOnlySpan<T>Though the ReadOnlySpan<T> is allocated on the stack, the underlying data on which the ReadOnlySpan<T> points to, may not be. 因此,透過ReadOnlySpan<T>進行列舉,本質上並不是安全線程的程式。Therefore, enumerating through a ReadOnlySpan<T> is intrinsically not a thread-safe procedure. 若要保證列舉期間的執行緒安全,您必須執行自己的同步處理。To guarantee thread safety during enumeration, you must implement your own synchronization.

不同于 .NET 中的ReadOnlySpan<T>.Enumerator其他一些列舉值結構,:Unlike some other enumerator structures in .NET, the ReadOnlySpan<T>.Enumerator:

屬性

Current Current Current Current

取得位於目前列舉值位置的項目參考。Gets a reference to the item at the current position of the enumerator.

方法

MoveNext() MoveNext() MoveNext() MoveNext()

將列舉值前移至 ReadOnlySpan<T> 的下一個項目。Advances the enumerator to the next item of the ReadOnlySpan<T>.

適用於