Movatterモバイル変換


[0]ホーム

URL:


Skip to main contentSkip to in-page navigation

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

Span<T> Struct

Definition

Namespace:
System
Assemblies:
netstandard.dll, System.Runtime.dll
Assembly:
System.Runtime.dll
Assembly:
System.Memory.dll
Assembly:
netstandard.dll
Package:
System.Memory v4.6.3
Source:
Span.cs
Source:
Span.cs
Source:
Span.cs
Source:
Span.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Provides a type-safe and memory-safe representation of a contiguous region of arbitrary memory.

generic <typename T>public value class Span
[System.Runtime.InteropServices.Marshalling.NativeMarshalling(typeof(System.Runtime.InteropServices.Marshalling.SpanMarshaller<,>))]public readonly ref struct Span<T>
public readonly ref struct Span<T>
[<System.Runtime.InteropServices.Marshalling.NativeMarshalling(typeof(System.Runtime.InteropServices.Marshalling.SpanMarshaller<,>))>]type Span<'T> = struct
type Span<'T> = struct
Public Structure Span(Of T)

Type Parameters

T

The type of items in theSpan<T>.

Inheritance
Attributes

Remarks

For more information about this API, seeSupplemental API remarks for Span<T>.

Constructors

Span<T>(T)

Creates a newSpan<T> of length 1 around the specified reference.

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

Creates a newSpan<T> object that includes a specified number of elements of an array starting at a specified index.

Span<T>(T[])

Creates a newSpan<T> object over the entirety of a specified array.

Span<T>(Void*, Int32)

Creates a newSpan<T> object from a specified number ofT elements starting at a specified memory address.

Properties

Empty

Returns an emptySpan<T> object.

IsEmpty

Returns a value that indicates whether the currentSpan<T> is empty.

Item[Int32]

Gets the element at the specified zero-based index.

Length

Returns the length of the current span.

Methods

Clear()

Clears the contents of thisSpan<T> object.

CopyTo(Span<T>)

Copies the contents of thisSpan<T> into a destinationSpan<T>.

Equals(Object)
Obsolete.
Obsolete.

Calls to this method are not supported.

Fill(T)

Fills the elements of this span with a specified value.

GetEnumerator()

Returns an enumerator for thisSpan<T>.

GetHashCode()
Obsolete.

Throws aNotSupportedException.

GetPinnableReference()

Returns a reference to an object of type T that can be used for pinning.

This method is intended to support .NET compilers and is not intended to be called by user code.

Slice(Int32, Int32)

Forms a slice out of the current span starting at a specified index for a specified length.

Slice(Int32)

Forms a slice out of the current span that begins at a specified index.

ToArray()

Copies the contents of this span into a new array.

ToString()

Returns the string representation of thisSpan<T> object.

TryCopyTo(Span<T>)

Attempts to copy the currentSpan<T> to a destinationSpan<T> and returns a value that indicates whether the copy operation succeeded.

Operators

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

Returns a value that indicates whether twoSpan<T> objects are equal.

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

Defines an implicit conversion of anArraySegment<T> to aSpan<T>.

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

Defines an implicit conversion of aSpan<T> to aReadOnlySpan<T>.

Implicit(T[] to Span<T>)

Defines an implicit conversion of an array to aSpan<T>.

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

Returns a value that indicates whether twoSpan<T> objects are not equal.

Extension Methods

ToImmutableArray<T>(Span<T>)

Converts the span to an immutable array.

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

Searches an entire sortedSpan<T> for a value using the specifiedIComparable<T> generic interface.

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

Searches an entire sortedSpan<T> for a specified value using the specifiedTComparer generic type.

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

Searches an entire sortedSpan<T> for a value using the specifiedTComparable generic type.

CommonPrefixLength<T>(Span<T>, ReadOnlySpan<T>, IEqualityComparer<T>)

Finds the length of any common prefix shared betweenspan andother.

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

Finds the length of any common prefix shared betweenspan andother.

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

Indicates whether a specified value is found in a span. Values are compared using IEquatable{T}.Equals(T).

ContainsAny<T>(Span<T>, T, T, T)

Searches for an occurrence ofvalue0,value1, orvalue2, and returnstrue if found. If not found, returnsfalse.

ContainsAny<T>(Span<T>, T, T)

Searches for an occurrence ofvalue0 orvalue1, and returnstrue if found. If not found, returnsfalse.

ContainsAny<T>(Span<T>, SearchValues<T>)

Searches for an occurrence of any of the specifiedvalues and returnstrue if found. If not found, returnsfalse.

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

Searches for an occurrence of any of the specifiedvalues and returnstrue if found. If not found, returnsfalse.

ContainsAnyExcept<T>(Span<T>, T, T, T)

Searches for any value other thanvalue0,value1, orvalue2.

ContainsAnyExcept<T>(Span<T>, T, T)

Searches for any value other thanvalue0 orvalue1.

ContainsAnyExcept<T>(Span<T>, T)

Searches for any value other than the specifiedvalue.

ContainsAnyExcept<T>(Span<T>, SearchValues<T>)

Searches for any value other than the specifiedvalues.

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

Searches for any value other than the specifiedvalues.

ContainsAnyExceptInRange<T>(Span<T>, T, T)

Searches for any value outside of the range betweenlowInclusive andhighInclusive, inclusive.

ContainsAnyInRange<T>(Span<T>, T, T)

Searches for any value in the range betweenlowInclusive andhighInclusive, inclusive, and returnstrue if found. If not found, returnsfalse.

Count<T>(Span<T>, T)

Counts the number of times the specifiedvalue occurs in thespan.

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

Counts the number of times the specifiedvalue occurs in thespan.

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

Determines whether the specified sequence appears at the end of a span.

IndexOf<T>(Span<T>, T)

Searches for the specified value and returns the index of its first occurrence. Values are compared using IEquatable{T}.Equals(T).

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

Searches for the specified sequence and returns the index of its first occurrence. Values are compared using IEquatable{T}.Equals(T).

IndexOfAny<T>(Span<T>, T, T, T)

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)

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>, SearchValues<T>)

Searches for the first index of any of the specified values.

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

Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator.

IndexOfAnyExcept<T>(Span<T>, T, T, T)

Searches for the first index of any value other than the specifiedvalue0,value1, orvalue2.

IndexOfAnyExcept<T>(Span<T>, T, T)

Searches for the first index of any value other than the specifiedvalue0 orvalue1.

IndexOfAnyExcept<T>(Span<T>, T)

Searches for the first index of any value other than the specifiedvalue.

IndexOfAnyExcept<T>(Span<T>, SearchValues<T>)

Searches for the first index of any value other than the specifiedvalues.

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

Searches for the first index of any value other than the specifiedvalues.

IndexOfAnyExceptInRange<T>(Span<T>, T, T)

Searches for the first index of any value outside of the range betweenlowInclusive andhighInclusive, inclusive.

IndexOfAnyInRange<T>(Span<T>, T, T)

Searches for the first index of any value in the range betweenlowInclusive andhighInclusive, inclusive.

LastIndexOf<T>(Span<T>, T)

Searches for the specified value and returns the index of its last occurrence. Values are compared using IEquatable{T}.Equals(T).

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

Searches for the specified sequence and returns the index of its last occurrence. Values are compared using IEquatable{T}.Equals(T).

LastIndexOfAny<T>(Span<T>, T, T, T)

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)

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>, SearchValues<T>)

Searches for the last index of any of the specified values.

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

Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator.

LastIndexOfAnyExcept<T>(Span<T>, T, T, T)

Searches for the last index of any value other than the specifiedvalue0,value1, orvalue2.

LastIndexOfAnyExcept<T>(Span<T>, T, T)

Searches for the last index of any value other than the specifiedvalue0 orvalue1.

LastIndexOfAnyExcept<T>(Span<T>, T)

Searches for the last index of any value other than the specifiedvalue.

LastIndexOfAnyExcept<T>(Span<T>, SearchValues<T>)

Searches for the last index of any value other than the specifiedvalues.

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

Searches for the last index of any value other than the specifiedvalues.

LastIndexOfAnyExceptInRange<T>(Span<T>, T, T)

Searches for the last index of any value outside of the range betweenlowInclusive andhighInclusive, inclusive.

LastIndexOfAnyInRange<T>(Span<T>, T, T)

Searches for the last index of any value in the range betweenlowInclusive andhighInclusive, inclusive.

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

Determines whether a span and a read-only span overlap in memory and outputs the element offset.

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

Determines whether a span and a read-only span overlap in memory.

Replace<T>(Span<T>, T, T, IEqualityComparer<T>)
Replace<T>(Span<T>, T, T)

Replaces all occurrences ofoldValue withnewValue.

ReplaceAny<T>(Span<T>, SearchValues<T>, T)
ReplaceAnyExcept<T>(Span<T>, SearchValues<T>, T)
Reverse<T>(Span<T>)

Reverses the sequence of the elements in the entire span.

SequenceCompareTo<T>(Span<T>, ReadOnlySpan<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>, IEqualityComparer<T>)

Determines whether two sequences are equal by comparing the elements using anIEqualityComparer<T>.

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

Determines whether a span and a read-only span are equal by comparing the elements using IEquatable{T}.Equals(T).

Sort<T>(Span<T>, Comparison<T>)

Sorts the elements in the entireSpan<T> using the specifiedComparison<T>.

Sort<T>(Span<T>)

Sorts the elements in the entireSpan<T> using theIComparable<T> implementation of each element of theSpan<T>.

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

Sorts the elements in the entireSpan<T> using theTComparer.

Sort<TKey,TValue>(Span<TKey>, Span<TValue>, Comparison<TKey>)

Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the firstSpan<T> using the specified comparison.

Sort<TKey,TValue>(Span<TKey>, Span<TValue>)

Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the firstSpan<T> using theIComparable<T> implementation of each key.

Sort<TKey,TValue,TComparer>(Span<TKey>, Span<TValue>, TComparer)

Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the firstSpan<T> using the specified comparer.

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

Determines whether a specified sequence appears at the start of a span.

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

Removes all leading and trailing occurrences of a specified element from a span.

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)

Removes all trailing occurrences of a specified element from a span.

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)

Removes all leading occurrences of a specified element from the span.

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

Removes all leading occurrences of a set of elements specified in a read-only span from the span.

Applies to

See also

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo