ReadOnlySpan<T> ReadOnlySpan<T> ReadOnlySpan<T> ReadOnlySpan<T> Struct

定義

提供任意記憶體之連續區域的型別安全和記憶體安全唯讀表示。Provides a type-safe and memory-safe read-only representation of a contiguous region of arbitrary memory.

generic <typename T>
public value class ReadOnlySpan
public struct ReadOnlySpan<T>
type ReadOnlySpan<'T> = struct
Public Structure ReadOnlySpan(Of T)

類型參數

T

中的專案類型ReadOnlySpan<T>The type of items in the ReadOnlySpan<T>.

繼承
ReadOnlySpan<T>ReadOnlySpan<T>ReadOnlySpan<T>ReadOnlySpan<T>

備註

ReadOnlySpan<T>是在堆疊上配置的ref 結構,而且永遠不能將它換成 managed 堆積。ReadOnlySpan<T> is a ref struct that is allocated on the stack and can never escape to the managed heap. Ref 結構類型有一些限制,以確保它們無法升級為 managed 堆積,包括無法以 lambda 運算式來進行裝箱、已指派給類型Object的變數、 dynamic指派給變數,以及它們無法執行任何介面類別型。Ref struct types have a number of restrictions to ensure that they cannot be promoted to the managed heap, including that they can't be boxed, captured in lambda expressions, assigned to variables of type Object, assigned to dynamic variables, and they cannot implement any interface type.

ReadOnlySpan<T>實例通常用來參考陣列的元素或陣列的一部分。A ReadOnlySpan<T> instance is often used to reference the elements of an array or a portion of an array. 不過,與陣列不同的是ReadOnlySpan<T> ,實例可以指向 managed 記憶體、原生記憶體或堆疊上管理的記憶體。Unlike an array, however, a ReadOnlySpan<T> instance can point to managed memory, native memory, or memory managed on the stack.

建構函式

ReadOnlySpan<T>(T[]) ReadOnlySpan<T>(T[]) ReadOnlySpan<T>(T[]) ReadOnlySpan<T>(T[])

在整個指定的陣列上建立新的 ReadOnlySpan<T>Creates a new ReadOnlySpan<T> over the entirety of a specified array.

ReadOnlySpan<T>(Void*, Int32) ReadOnlySpan<T>(Void*, Int32) ReadOnlySpan<T>(Void*, Int32) ReadOnlySpan<T>(Void*, Int32)

透過指定的 T 元素數目建立新 ReadOnlySpan<T>,從指定的記憶體位址開始。Creates a new ReadOnlySpan<T> from a specified number of T elements starting at a specified memory address.

ReadOnlySpan<T>(T[], Int32, Int32) ReadOnlySpan<T>(T[], Int32, Int32) ReadOnlySpan<T>(T[], Int32, Int32) ReadOnlySpan<T>(T[], Int32, Int32)

建立新的 ReadOnlySpan<T>,其中包含起始於指定索引之陣列的指定元素數目。Creates a new ReadOnlySpan<T> that includes a specified number of elements of an array starting at a specified index.

屬性

Empty Empty Empty Empty

傳回空的 ReadOnlySpan<T>Returns an empty ReadOnlySpan<T>.

IsEmpty IsEmpty IsEmpty IsEmpty

傳回指出目前唯讀範圍是空的的值。Returns a value that indicates the current read-only span is empty.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

從位於指定零基索引的唯讀範圍取得項目。Gets an item from the read-only span at the specified zero-based index.

Length Length Length Length

唯讀範圍中的項目數目。The number of items in the read-only span.

方法

CopyTo(Span<T>) CopyTo(Span<T>) CopyTo(Span<T>) CopyTo(Span<T>)

將這個 ReadOnlySpan<T> 的內容複製到目的地 Span<T>Copies the contents of this ReadOnlySpan<T> into a destination Span<T>.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

不支援。Not supported. 擲回 NotSupportedExceptionThrows a NotSupportedException.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

傳回這個 ReadOnlySpan<T> 的列舉值。Returns an enumerator for this ReadOnlySpan<T>.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

不支援。Not supported. 擲回 NotSupportedExceptionThrows a NotSupportedException.

GetPinnableReference() GetPinnableReference() GetPinnableReference() GetPinnableReference()

可用於釘選,且為在 fixed 陳述式中支援使用延伸之必要項的類型 T 物件唯讀參考。A read-only reference to an object of type T that can be used for pinning, and is required to support the use of span within a fixed statement.

Slice(Int32) Slice(Int32) Slice(Int32) Slice(Int32)

從起始於指定索引的目前唯讀範圍形成配量。Forms a slice out of the current read-only span that begins at a specified index.

Slice(Int32, Int32) Slice(Int32, Int32) Slice(Int32, Int32) Slice(Int32, Int32)

從起始於指定索引之指定長度的目前唯讀範圍形成配量。Forms a slice out of the current read-only span starting at a specified index for a specified length.

ToArray() ToArray() ToArray() ToArray()

將這個唯讀範圍的內容複製到新的陣列。Copies the contents of this read-only span into a new array.

ToString() ToString() ToString() ToString()

傳回這個 ReadOnlySpan<T> 的字串表示。Returns the string representation of this ReadOnlySpan<T>.

TryCopyTo(Span<T>) TryCopyTo(Span<T>) TryCopyTo(Span<T>) TryCopyTo(Span<T>)

嘗試將此 ReadOnlySpan<T> 的內容複製到 Span<T> 並傳回指出作業是否成功的值。Attempts to copy the contents of this ReadOnlySpan<T> into a Span<T> and returns a value to indicate whether or not the operation succeeded.

運算子

Equality(ReadOnlySpan<T>, ReadOnlySpan<T>) Equality(ReadOnlySpan<T>, ReadOnlySpan<T>) Equality(ReadOnlySpan<T>, ReadOnlySpan<T>) Equality(ReadOnlySpan<T>, ReadOnlySpan<T>)

傳回值,這個值表示兩個 ReadOnlySpan<T> 執行個體是否相等。Returns a value that indicates whether two ReadOnlySpan<T> instances are equal.

Implicit(ArraySegment<T> to ReadOnlySpan<T>) Implicit(ArraySegment<T> to ReadOnlySpan<T>) Implicit(ArraySegment<T> to ReadOnlySpan<T>) Implicit(ArraySegment<T> to ReadOnlySpan<T>)

定義從 ArraySegment<T>ReadOnlySpan<T> 的隱含轉換。Defines an implicit conversion of an ArraySegment<T> to a ReadOnlySpan<T>.

Implicit(T[] to ReadOnlySpan<T>) Implicit(T[] to ReadOnlySpan<T>) Implicit(T[] to ReadOnlySpan<T>) Implicit(T[] to ReadOnlySpan<T>)

定義從陣列到 ReadOnlySpan<T> 的隱含轉換。Defines an implicit conversion of an array to a ReadOnlySpan<T>.

Inequality(ReadOnlySpan<T>, ReadOnlySpan<T>) Inequality(ReadOnlySpan<T>, ReadOnlySpan<T>) Inequality(ReadOnlySpan<T>, ReadOnlySpan<T>) Inequality(ReadOnlySpan<T>, ReadOnlySpan<T>)

傳回值,這個值表示兩個 ReadOnlySpan<T> 執行個體是否不相等。Returns a value that indicates whether two ReadOnlySpan<T> instances are not equal.

擴充方法

BinarySearch<T>(ReadOnlySpan<T>, IComparable<T>) BinarySearch<T>(ReadOnlySpan<T>, IComparable<T>) BinarySearch<T>(ReadOnlySpan<T>, IComparable<T>) BinarySearch<T>(ReadOnlySpan<T>, IComparable<T>)

使用指定的 IComparable<T> 泛型介面,在整個已排序的 ReadOnlySpan<T> 中搜尋值。Searches an entire sorted ReadOnlySpan<T> for a value using the specified IComparable<T> generic interface.

BinarySearch<T,TComparer>(ReadOnlySpan<T>, T, TComparer) BinarySearch<T,TComparer>(ReadOnlySpan<T>, T, TComparer) BinarySearch<T,TComparer>(ReadOnlySpan<T>, T, TComparer) BinarySearch<T,TComparer>(ReadOnlySpan<T>, T, TComparer)

使用指定的 TComparer 泛型型別,在整個已排序的 ReadOnlySpan<T> 中搜尋指定的值。Searches an entire sorted ReadOnlySpan<T> for a specified value using the specified TComparer generic type.

BinarySearch<T,TComparable>(ReadOnlySpan<T>, TComparable) BinarySearch<T,TComparable>(ReadOnlySpan<T>, TComparable) BinarySearch<T,TComparable>(ReadOnlySpan<T>, TComparable) BinarySearch<T,TComparable>(ReadOnlySpan<T>, TComparable)

使用指定的 TComparable 泛型型別,在整個已排序的 ReadOnlySpan<T> 中搜尋值。Searches an entire sorted ReadOnlySpan<T> for a value using the specified TComparable generic type.

Contains<T>(ReadOnlySpan<T>, T) Contains<T>(ReadOnlySpan<T>, T) Contains<T>(ReadOnlySpan<T>, T) Contains<T>(ReadOnlySpan<T>, T)

指出是否在唯讀範圍中找到指定的值。Indicates whether a specified value is found in a read-only span. 值是使用 IEquatable{T}.Equals(T) 來進行比較。Values are compared using IEquatable{T}.Equals(T).

EndsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) EndsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) EndsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) EndsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

判斷所指定序列是否出現在唯讀範圍的結尾。Determines whether the specified sequence appears at the end of a read-only span.

IndexOf<T>(ReadOnlySpan<T>, T) IndexOf<T>(ReadOnlySpan<T>, T) IndexOf<T>(ReadOnlySpan<T>, T) IndexOf<T>(ReadOnlySpan<T>, T)

搜尋指定的值,並傳回第一個出現位置的索引。Searches for the specified value and returns the index of its first occurrence. 值是使用 IEquatable{T}.Equals(T) 來進行比較。Values are compared using IEquatable{T}.Equals(T).

IndexOf<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) IndexOf<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) IndexOf<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) IndexOf<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

搜尋指定的序列,並傳回第一個出現位置的索引。Searches for the specified sequence and returns the index of its first occurrence. 值是使用 IEquatable{T}.Equals(T) 來進行比較。Values are compared using IEquatable{T}.Equals(T).

IndexOfAny<T>(ReadOnlySpan<T>, T, T) IndexOfAny<T>(ReadOnlySpan<T>, T, T) IndexOfAny<T>(ReadOnlySpan<T>, T, T) IndexOfAny<T>(ReadOnlySpan<T>, T, T)

搜尋任何指定值的第一個索引,類似於使用邏輯 OR 運算子呼叫 IndexOf 多次。Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator.

IndexOfAny<T>(ReadOnlySpan<T>, T, T, T) IndexOfAny<T>(ReadOnlySpan<T>, T, T, T) IndexOfAny<T>(ReadOnlySpan<T>, T, T, T) IndexOfAny<T>(ReadOnlySpan<T>, T, T, T)

搜尋任何指定值的第一個索引,類似於使用邏輯 OR 運算子呼叫 IndexOf 多次。Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator.

IndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) IndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) IndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) IndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

搜尋任何指定值的第一個索引,類似於使用邏輯 OR 運算子呼叫 IndexOf 多次。Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator.

LastIndexOf<T>(ReadOnlySpan<T>, T) LastIndexOf<T>(ReadOnlySpan<T>, T) LastIndexOf<T>(ReadOnlySpan<T>, T) LastIndexOf<T>(ReadOnlySpan<T>, T)

搜尋指定的值,並傳回最後一個出現位置的索引。Searches for the specified value and returns the index of its last occurrence. 值是使用 IEquatable{T}.Equals(T) 來進行比較。Values are compared using IEquatable{T}.Equals(T).

LastIndexOf<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) LastIndexOf<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) LastIndexOf<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) LastIndexOf<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

搜尋指定的序列,並傳回最後一個出現位置的索引。Searches for the specified sequence and returns the index of its last occurrence. 值是使用 IEquatable{T}.Equals(T) 來進行比較。Values are compared using IEquatable{T}.Equals(T).

LastIndexOfAny<T>(ReadOnlySpan<T>, T, T) LastIndexOfAny<T>(ReadOnlySpan<T>, T, T) LastIndexOfAny<T>(ReadOnlySpan<T>, T, T) LastIndexOfAny<T>(ReadOnlySpan<T>, T, T)

搜尋任何指定值的最後一個索引,類似於使用邏輯 OR 運算子呼叫 LastIndexOf 多次。Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator.

LastIndexOfAny<T>(ReadOnlySpan<T>, T, T, T) LastIndexOfAny<T>(ReadOnlySpan<T>, T, T, T) LastIndexOfAny<T>(ReadOnlySpan<T>, T, T, T) LastIndexOfAny<T>(ReadOnlySpan<T>, T, T, T)

搜尋任何指定值的最後一個索引,類似於使用邏輯 OR 運算子呼叫 LastIndexOf 多次。Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator.

LastIndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) LastIndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) LastIndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) LastIndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

搜尋任何指定值的最後一個索引,類似於使用邏輯 OR 運算子呼叫 LastIndexOf 多次。Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator.

Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

判斷兩個唯讀序列在記憶體中是否重疊。Determines whether two read-only sequences overlap in memory.

Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>, Int32) Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>, Int32) Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>, Int32) Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>, Int32)

判斷兩個唯讀序列在記憶體中是否重疊,並輸出元素位移。Determines whether two read-only sequences overlap in memory and outputs the element offset.

SequenceCompareTo<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceCompareTo<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceCompareTo<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceCompareTo<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

使用 IComparable{T}.CompareTo(T) 來比較其元素,判斷兩個唯讀序列的相對順序。Determines the relative order of two read-only sequences by comparing their elements using IComparable{T}.CompareTo(T).

SequenceEqual<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceEqual<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceEqual<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceEqual<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

使用 IEquatable{T}.Equals(T) 來比較元素,判斷兩個唯讀序列是否相等。Determines whether two read-only sequences are equal by comparing the elements using IEquatable{T}.Equals(T).

StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

判斷所指定序列是否出現在唯讀範圍的開頭。Determines whether a specified sequence appears at the start of a read-only span.

Trim<T>(ReadOnlySpan<T>, T) Trim<T>(ReadOnlySpan<T>, T) Trim<T>(ReadOnlySpan<T>, T) Trim<T>(ReadOnlySpan<T>, T)

從唯讀範圍中移除所有開頭和尾端指定元素項目。Removes all leading and trailing occurrences of a specified element from a read-only span.

Trim<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) Trim<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) Trim<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) Trim<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

從唯讀範圍中移除唯讀範圍中指定的所有開頭和尾端元素集項目。Removes all leading and trailing occurrences of a set of elements specified in a read-only span from a read-only span.

TrimEnd<T>(ReadOnlySpan<T>, T) TrimEnd<T>(ReadOnlySpan<T>, T) TrimEnd<T>(ReadOnlySpan<T>, T) TrimEnd<T>(ReadOnlySpan<T>, T)

從唯讀範圍中移除所有尾端指定元素項目。Removes all trailing occurrences of a specified element from a read-only span.

TrimEnd<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) TrimEnd<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) TrimEnd<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) TrimEnd<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

從唯讀範圍中移除唯讀範圍中指定的所有尾端元素集項目。Removes all trailing occurrences of a set of elements specified in a read-only span from a read-only span.

TrimStart<T>(ReadOnlySpan<T>, T) TrimStart<T>(ReadOnlySpan<T>, T) TrimStart<T>(ReadOnlySpan<T>, T) TrimStart<T>(ReadOnlySpan<T>, T)

從範圍中移除所有開頭指定元素項目。Removes all leading occurrences of a specified element from the span.

TrimStart<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) TrimStart<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) TrimStart<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) TrimStart<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

從範圍中移除唯讀範圍中指定的所有開頭元素集項目。Removes all leading occurrences of a set of elements specified in a read-only span from the span.

適用於