Span<T> Span<T> Span<T> Span<T> Struct

定义

提供任意内存的连续区域的类型和内存安全表示。Provides a type- and memory-safe representation of a contiguous region of arbitrary memory.

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

类型参数

T

中项的类型Span<T>The type of items in the Span<T>.

继承

注解

Span<T>是在堆栈上分配的引用结构, 而不是在托管堆上分配的。Span<T> is a ref struct that is allocated on the stack rather than on the managed heap. Ref 结构类型具有多个限制, 可确保无法将它们升级到托管堆, 其中包括不能装箱、不能将其分配给类型Object dynamic的变量或任何接口类型, 它们不能是中的字段引用类型, 不能跨awaityield边界使用。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, they can't be assigned to variables of type Object, dynamic or to any interface type, they can't be fields in a reference type, and they can't be used across await and yield boundaries. 此外, 对两个方法Equals(Object)GetHashCode的调用将引发NotSupportedExceptionIn addition, calls to two methods, Equals(Object) and GetHashCode, throw a NotSupportedException.

重要

由于它是仅堆栈类型, Span<T>因此对于需要在堆上存储缓冲区引用的多个方案是不合适的。Because it is a stack-only type, Span<T> is unsuitable for many scenarios that require storing references to buffers on the heap. 例如, 这是执行异步方法调用的例程。This is true, for example, of routines that make asynchronous method calls. 对于这种情况, 可以使用互补System.Memory<T>System.ReadOnlyMemory<T>类型。For such scenarios, you can use the complementary System.Memory<T> and System.ReadOnlyMemory<T> types.

对于表示不可变或只读结构的范围, 请使用System.ReadOnlySpan<T>For spans that represent immutable or read-only structures, use System.ReadOnlySpan<T>.

跨度<T > 和内存Span<T> and memory

Span<T>表示任意内存的连续区域。A Span<T> represents a contiguous region of arbitrary memory. Span<T>实例通常用于保存数组或某个数组的一部分的元素。A Span<T> instance is often used to hold the elements of an array or a portion of an array. 但与数组不同, Span<T>实例可以指向托管内存、本机内存或在堆栈上管理的内存。Unlike an array, however, a Span<T> instance can point to managed memory, native memory, or memory managed on the stack. 下面的示例Span<Byte>从数组创建:The following example creates a Span<Byte> from an array:

// Create a span over an array.
var array = new byte[100];
var arraySpan = new Span<byte>(array);

byte data = 0;
for (int ctr = 0; ctr < arraySpan.Length; ctr++)
    arraySpan[ctr] = data++;

int arraySum = 0;
foreach (var value in array)
    arraySum += value;

Console.WriteLine($"The sum is {arraySum}");
// Output:  The sum is 4950

下面的示例创建一个Span<Byte> 100 字节的本机内存:The following example creates a Span<Byte> from 100 bytes of native memory:

// Create a span from native memory.
var native = Marshal.AllocHGlobal(100);
Span<byte> nativeSpan;
unsafe
{
    nativeSpan = new Span<byte>(native.ToPointer(), 100);
}
byte data = 0;
for (int ctr = 0; ctr < nativeSpan.Length; ctr++)
    nativeSpan[ctr] = data++;

int nativeSum = 0;
foreach (var value in nativeSpan)
    nativeSum += value;

Console.WriteLine($"The sum is {nativeSum}");
Marshal.FreeHGlobal(native);
// Output:  The sum is 4950

下面的示例使用C# stackalloc关键字在堆栈上分配100字节的内存:The following example uses the C# stackalloc keyword to allocate 100 bytes of memory on the stack:

// Create a span on the stack.
byte data = 0;
Span<byte> stackSpan = stackalloc byte[100];
for (int ctr = 0; ctr < stackSpan.Length; ctr++)
    stackSpan[ctr] = data++;

int stackSum = 0;
foreach (var value in stackSpan)
    stackSum += value;

Console.WriteLine($"The sum is {stackSum}");
// Output:  The sum is 4950

由于Span<T>是任意内存块的抽象, 因此具有Span<T>参数的Span<T>类和方法的方法将在任何Span<T>对象上操作, 而不考虑它所封装的内存类型。Because Span<T> is an abstraction over an arbitrary block of memory, methods of the Span<T> class and methods with Span<T> parameters operate on any Span<T> object regardless of the kind of memory it encapsulates. 例如, 初始化范围并计算其元素的总和的代码的每个单独部分均可更改为单一初始化和计算方法, 如以下示例所示:For example, each of the separate sections of code that initialize the span and calculate the sum of its elements can be changed into single initialization and calculation methods, as the following example illustrates:

public static void WorkWithSpans()
{
    // Create a span over an array.
    var array = new byte[100];
    var arraySpan = new Span<byte>(array);
    
    InitializeSpan(arraySpan);
    Console.WriteLine($"The sum is {ComputeSum(arraySpan):N0}");

    // Create an array from native memory.
    var native = Marshal.AllocHGlobal(100);
    Span<byte> nativeSpan;
    unsafe
    {
        nativeSpan = new Span<byte>(native.ToPointer(), 100);
    }

    InitializeSpan(nativeSpan);
    Console.WriteLine($"The sum is {ComputeSum(nativeSpan):N0}");
    
    Marshal.FreeHGlobal(native);

    // Create a span on the stack.
    Span<byte> stackSpan = stackalloc byte[100];

    InitializeSpan(stackSpan);
    Console.WriteLine($"The sum is {ComputeSum(stackSpan):N0}");
}

public static void InitializeSpan(Span<byte> span)
{
    byte value = 0;
    for (int ctr = 0; ctr < span.Length; ctr++)
        span[ctr] = value++;
}

public static int ComputeSum(Span<byte> span)
{
    int sum = 0;
    foreach (var value in span)
        sum += value;

    return sum;
}
// The example displays the following output:
//    The sum is 4,950
//    The sum is 4,950
//    The sum is 4,950

跨度<T > 和数组Span<T> and arrays

包装数组时, Span<T>可以包装整个数组, 这与在> 和 memory<部分的示例中所做的一样。When it wraps an array, Span<T> can wrap an entire array, as it did in the examples in the Span<T> and memory section. 由于它支持切片, Span<T>因此还可以指向数组内的任何连续范围。Because it supports slicing, Span<T> can also point to any contiguous range within the array.

下面的示例创建一个10元素整数数组中间5个元素的切片。The following example creates a slice of the middle five elements of a 10-element integer array. 请注意, 该代码会将切片中每个整数的值加倍。Note that the code doubles the values of each integer in the slice. 正如输出所示, 范围内的更改会反映在数组的值中。As the output shows, the changes made by the span are reflected in the values of the array.

using System;

namespace span
{
    class Program
    {
        static void Main(string[] args)
        {
            var array = new int[] { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };
            var slice = new Span<int>(array, 2, 5);
            for (int ctr = 0; ctr < slice.Length; ctr++)
               slice[ctr] *= 2;
            
            // Examine the original array values.
            foreach (var value in array)
                Console.Write($"{value}  ");
            Console.WriteLine();
        }
    }
}
// The example displays the following output:
//      2  4  12  16  20  24  28  16  18  20

跨度<T > 和切片Span<T> and slices

Span<T>包含Slice方法的两个重载, 该方法构成从指定索引处开始的当前范围的切片。Span<T> includes two overloads of the Slice method that form a slice out of the current span that starts at a specified index. 这样一来, 就可以将中Span<T>的数据作为一组逻辑块进行处理, 数据处理管道的部分可以按需处理这些数据块, 并对性能的影响最小。This makes it possible to treat the data in a Span<T> as a set of logical chunks that can be processed as needed by portions of a data processing pipeline with minimal performance impact. 例如, 由于新式服务器协议通常基于文本, 因此字符串和子字符串的操作非常重要。For example, since modern server protocols are often text-based, manipulation of strings and substrings is particularly important. 在类中, 提取子字符串的主要方法是SubstringStringIn the String class, the major method for extracting substrings is Substring. 对于依赖于广泛的字符串操作的数据管道, 其使用会带来一些性能损失, 因为它:For data pipelines that rely on extensive string manipulation, its use offers some performance penalties, since it:

  1. 创建用于保存子字符串的新字符串。Creates a new string to hold the substring.

  2. 将原始字符串中的字符子集复制到新字符串中。Copies a subset of the characters from the original string to the new string.

可以使用Span<T>ReadOnlySpan<T>删除此分配和复制操作, 如下面的示例所示:This allocation and copy operation can be eliminated by using either Span<T> or ReadOnlySpan<T>, as the following example shows:

using System;

class Program
{
    static void Main()
    {
        string contentLength = "Content-Length: 132";
        var length = GetContentLength(contentLength.ToCharArray());	
        Console.WriteLine($"Content length: {length}"); 
    }

    private static int GetContentLength(ReadOnlySpan<char> span)
    {
        var slice = span.Slice(16);
	    return int.Parse(slice);	
    }
}
// Output:
//      Content length: 132

构造函数

Span<T>(T[]) Span<T>(T[]) Span<T>(T[]) Span<T>(T[])

在整个指定数组上创建新的 Span<T> 对象。Creates a new Span<T> object over the entirety of a specified array.

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

从指定的内存地址开始,从指定 T 元素数创建新的 Span<T> 对象。Creates a new Span<T> object from a specified number of T elements starting at a specified memory address.

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

从指定索引开始,创建包含数组的指定元素数的新 Span<T> 对象。Creates a new Span<T> object that includes a specified number of elements of an array starting at a specified index.

属性

Empty Empty Empty Empty

返回空的 Span<T> 对象。Returns an empty Span<T> object.

IsEmpty IsEmpty IsEmpty IsEmpty

返回一个值,该值指示当前的 Span<T> 是否为空。Returns a value that indicates whether the current Span<T> is empty.

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

获取指定基于零的索引处的元素。Gets the element at the specified zero-based index.

Item[Index] Item[Index] Item[Index] Item[Index]
Length Length Length Length

返回当前范围的长度。Returns the length of the current span.

方法

Clear() Clear() Clear() Clear()

清除此 Span<T> 对象的内容。Clears the contents of this Span<T> object.

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

将此 Span<T> 的内容复制到目标 Span<T>Copies the contents of this Span<T> into a destination Span<T>.

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

不支持对此方法的调用。Calls to this method are not supported.

Fill(T) Fill(T) Fill(T) Fill(T)

用指定的值填充此范围的元素。Fills the elements of this span with a specified value.

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

返回用于此 Span<T> 的枚举器。Returns an enumerator for this Span<T>.

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

引发 NotSupportedExceptionThrows a NotSupportedException.

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

返回对索引为零处 Span<T> 元素的引用。Returns a reference to the element of the Span<T> at index zero.

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

从指定索引处开始的当前范围外形成切片。Forms a slice out of the current span that begins at a specified index.

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

从指定长度的指定索引处开始,在当前范围外形成切片。Forms a slice out of the current span starting at a specified index for a specified length.

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

将此范围的内容复制到新数组中。Copies the contents of this span into a new array.

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

返回此 Span<T> 对象的字符串表示形式。Returns the string representation of this Span<T> object.

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

尝试将当前 Span<T> 复制到目标 Span<T>,并返回一个指示复制操作是否成功的值。Attempts to copy the current Span<T> to a destination Span<T> and returns a value that indicates whether the copy operation succeeded.

操作员

Equality(Span<T>, Span<T>) Equality(Span<T>, Span<T>) Equality(Span<T>, Span<T>) Equality(Span<T>, Span<T>)

返回一个值,该值指示两个 Span<T> 对象是否相等。Returns a value that indicates whether two Span<T> objects are equal.

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

定义 ArraySegment<T>Span<T> 的隐式转换。Defines an implicit conversion of an ArraySegment<T> to a Span<T>.

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

定义 Span<T>ReadOnlySpan<T> 的隐式转换。Defines an implicit conversion of a Span<T> to a ReadOnlySpan<T>.

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

定义数组到 Span<T> 的隐式转换。Defines an implicit conversion of an array to a Span<T>.

Inequality(Span<T>, Span<T>) Inequality(Span<T>, Span<T>) Inequality(Span<T>, Span<T>) Inequality(Span<T>, Span<T>)

返回一个值,该值指示两个 Span<T> 对象是否不相等。Returns a value that indicates whether two Span<T> objects are not equal.

扩展方法

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

使用指定的 IComparable<T> 泛型接口,在整个已排序的 Span<T> 中搜索值。Searches an entire sorted Span<T> for a value using the specified IComparable<T> generic interface.

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

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

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

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

Contains<T>(Span<T>, T) Contains<T>(Span<T>, T) Contains<T>(Span<T>, T) Contains<T>(Span<T>, T)

指示是否在跨度内找到指定的值。Indicates whether a specified value is found in a span. 使用 IEquatable{T}.Equals(T) 比较各值。Values are compared using IEquatable{T}.Equals(T).

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

确定指定的序列是否出现在跨度的结尾。Determines whether the specified sequence appears at the end of a span.

IndexOf<T>(Span<T>, T) IndexOf<T>(Span<T>, T) IndexOf<T>(Span<T>, T) IndexOf<T>(Span<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>(Span<T>, ReadOnlySpan<T>) IndexOf<T>(Span<T>, ReadOnlySpan<T>) IndexOf<T>(Span<T>, ReadOnlySpan<T>) IndexOf<T>(Span<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>(Span<T>, T, T) IndexOfAny<T>(Span<T>, T, T) IndexOfAny<T>(Span<T>, T, T) IndexOfAny<T>(Span<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>(Span<T>, T, T, T) IndexOfAny<T>(Span<T>, T, T, T) IndexOfAny<T>(Span<T>, T, T, T) IndexOfAny<T>(Span<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>(Span<T>, ReadOnlySpan<T>) IndexOfAny<T>(Span<T>, ReadOnlySpan<T>) IndexOfAny<T>(Span<T>, ReadOnlySpan<T>) IndexOfAny<T>(Span<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>(Span<T>, T) LastIndexOf<T>(Span<T>, T) LastIndexOf<T>(Span<T>, T) LastIndexOf<T>(Span<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>(Span<T>, ReadOnlySpan<T>) LastIndexOf<T>(Span<T>, ReadOnlySpan<T>) LastIndexOf<T>(Span<T>, ReadOnlySpan<T>) LastIndexOf<T>(Span<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>(Span<T>, T, T) LastIndexOfAny<T>(Span<T>, T, T) LastIndexOfAny<T>(Span<T>, T, T) LastIndexOfAny<T>(Span<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>(Span<T>, T, T, T) LastIndexOfAny<T>(Span<T>, T, T, T) LastIndexOfAny<T>(Span<T>, T, T, T) LastIndexOfAny<T>(Span<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>(Span<T>, ReadOnlySpan<T>) LastIndexOfAny<T>(Span<T>, ReadOnlySpan<T>) LastIndexOfAny<T>(Span<T>, ReadOnlySpan<T>) LastIndexOfAny<T>(Span<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>(Span<T>, ReadOnlySpan<T>) Overlaps<T>(Span<T>, ReadOnlySpan<T>) Overlaps<T>(Span<T>, ReadOnlySpan<T>) Overlaps<T>(Span<T>, ReadOnlySpan<T>)

确定跨度和只读跨度是否在内存中重叠。Determines whether a span and a read-only span overlap in memory.

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

确定跨度和只读跨度是否在内存中重叠且输出元素偏移。Determines whether a span and a read-only span overlap in memory and outputs the element offset.

Reverse<T>(Span<T>) Reverse<T>(Span<T>) Reverse<T>(Span<T>) Reverse<T>(Span<T>)

反转整个跨度中元素的序列。Reverses the sequence of the elements in the entire span.

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

通过使用 IComparable{T}.CompareTo(T) 比较它们的元素,确定跨度和只读跨度的相对顺序。Determines the relative order of a span and a read-only span by comparing the elements using IComparable{T}.CompareTo(T).

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

通过使用 IEquatable{T}.Equals(T) 比较元素,确定跨度和只读跨度是否相等。Determines whether a span and a read-only span are equal by comparing the elements using IEquatable{T}.Equals(T).

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

确定指定的序列是否出现在跨度的开头。Determines whether a specified sequence appears at the start of a span.

Trim<T>(Span<T>, T) Trim<T>(Span<T>, T) Trim<T>(Span<T>, T) Trim<T>(Span<T>, T)

删除跨度中的指定元素的所有前导和尾随出现次数。Removes all leading and trailing occurrences of a specified element from a span.

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

从跨度中删除在只读跨度中指定的一组元素的所有前导和尾随出现次数。Removes all leading and trailing occurrences of a set of elements specified in a read-only span from a span.

TrimEnd<T>(Span<T>, T) TrimEnd<T>(Span<T>, T) TrimEnd<T>(Span<T>, T) TrimEnd<T>(Span<T>, T)

删除跨度中的指定元素的所有尾随出现次数。Removes all trailing occurrences of a specified element from a span.

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

从跨度中删除在只读跨度中指定的一组元素的所有尾随出现次数。Removes all trailing occurrences of a set of elements specified in a read-only span from a span.

TrimStart<T>(Span<T>, T) TrimStart<T>(Span<T>, T) TrimStart<T>(Span<T>, T) TrimStart<T>(Span<T>, T)

删除跨度中的指定元素的所有前导出现次数。Removes all leading occurrences of a specified element from the span.

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

从跨度中删除在只读跨度中指定的一组元素的所有前导出现次数。Removes all leading occurrences of a set of elements specified in a read-only span from the span.

适用于