ReadOnlySpan<T> Struct
Definition
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 read-only representation of a contiguous region of arbitrary memory.
generic <typename T>
public value class ReadOnlySpan
public readonly ref struct ReadOnlySpan<T>
[System.Runtime.InteropServices.Marshalling.NativeMarshalling(typeof(System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller<,>))]
public readonly ref struct ReadOnlySpan<T>
type ReadOnlySpan<'T> = struct
[<System.Runtime.InteropServices.Marshalling.NativeMarshalling(typeof(System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller<,>))>]
type ReadOnlySpan<'T> = struct
Public Structure ReadOnlySpan(Of T)
Type Parameters
- T
The type of items in the ReadOnlySpan<T>.
- Inheritance
- Attributes
Remarks
ReadOnlySpan<T>
is a ref struct that is allocated on the stack and can never escape to the managed heap. 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.
A ReadOnlySpan<T>
instance is often used to reference the elements of an array or a portion of an array. Unlike an array, however, a ReadOnlySpan<T>
instance can point to managed memory, native memory, or memory managed on the stack.
Constructors
ReadOnlySpan<T>(T) |
Creates a new ReadOnlySpan<T> of length 1 around the specified reference. |
ReadOnlySpan<T>(T[], Int32, Int32) |
Creates a new ReadOnlySpan<T> that includes a specified number of elements of an array starting at a specified index. |
ReadOnlySpan<T>(T[]) |
Creates a new ReadOnlySpan<T> over the entirety of a specified array. |
ReadOnlySpan<T>(Void*, Int32) |
Creates a new ReadOnlySpan<T> from a specified number of |
Properties
Empty |
Returns an empty ReadOnlySpan<T>. |
IsEmpty |
Returns a value that indicates the current read-only span is empty. |
Item[Int32] |
Gets an item from the read-only span at the specified zero-based index. |
Length |
The number of items in the read-only span. |
Methods
CastUp<TDerived>(ReadOnlySpan<TDerived>) |
Casts a read-only span of |
CopyTo(Span<T>) |
Copies the contents of this ReadOnlySpan<T> into a destination Span<T>. |
Equals(Object) |
Obsolete.
Obsolete.
Not supported. Throws a NotSupportedException. |
GetEnumerator() |
Returns an enumerator for this ReadOnlySpan<T>. |
GetHashCode() |
Obsolete.
Not supported. Throws a NotSupportedException. |
GetPinnableReference() |
Returns a read-only 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 read-only span starting at a specified index for a specified length. |
Slice(Int32) |
Forms a slice out of the current read-only span that begins at a specified index. |
ToArray() |
Copies the contents of this read-only span into a new array. |
ToString() |
Returns the string representation of this ReadOnlySpan<T>. |
TryCopyTo(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. |
Operators
Equality(ReadOnlySpan<T>, ReadOnlySpan<T>) |
Returns a value that indicates whether two ReadOnlySpan<T> instances are equal. |
Implicit(ArraySegment<T> to ReadOnlySpan<T>) |
Defines an implicit conversion of an ArraySegment<T> to a ReadOnlySpan<T>. |
Implicit(T[] to ReadOnlySpan<T>) |
Defines an implicit conversion of an array to a ReadOnlySpan<T>. |
Inequality(ReadOnlySpan<T>, ReadOnlySpan<T>) |
Returns a value that indicates whether two ReadOnlySpan<T> instances are not equal. |
Extension Methods
ToImmutableArray<T>(ReadOnlySpan<T>) |
Produce an immutable array of contents from specified elements. |
BinarySearch<T>(ReadOnlySpan<T>, IComparable<T>) |
Searches an entire sorted ReadOnlySpan<T> for a value using the specified IComparable<T> generic interface. |
BinarySearch<T,TComparer>(ReadOnlySpan<T>, T, TComparer) |
Searches an entire sorted ReadOnlySpan<T> for a specified value using the specified |
BinarySearch<T,TComparable>(ReadOnlySpan<T>, TComparable) |
Searches an entire sorted ReadOnlySpan<T> for a value using the specified |
CommonPrefixLength<T>(ReadOnlySpan<T>, ReadOnlySpan<T>, IEqualityComparer<T>) |
Determines the length of any common prefix shared between |
CommonPrefixLength<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) |
Finds the length of any common prefix shared between |
Contains<T>(ReadOnlySpan<T>, T) |
Indicates whether a specified value is found in a read-only span. Values are compared using IEquatable{T}.Equals(T). |
ContainsAny<T>(ReadOnlySpan<T>, T, T, T) |
Searches for an occurrence of |
ContainsAny<T>(ReadOnlySpan<T>, T, T) |
Searches for an occurrence of |
ContainsAny<T>(ReadOnlySpan<T>, SearchValues<T>) |
Searches for an occurrence of any of the specified |
ContainsAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) |
Searches for an occurrence of any of the specified |
ContainsAnyExcept<T>(ReadOnlySpan<T>, T, T, T) |
Searches for any value other than |
ContainsAnyExcept<T>(ReadOnlySpan<T>, T, T) |
Searches for any value other than |
ContainsAnyExcept<T>(ReadOnlySpan<T>, T) |
Searches for any value other than the specified |
ContainsAnyExcept<T>(ReadOnlySpan<T>, SearchValues<T>) |
Searches for any value other than the specified |
ContainsAnyExcept<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) |
Searches for any value other than the specified |
ContainsAnyExceptInRange<T>(ReadOnlySpan<T>, T, T) |
Searches for any value outside of the range between |
ContainsAnyInRange<T>(ReadOnlySpan<T>, T, T) |
Searches for any value in the range between |
Count<T>(ReadOnlySpan<T>, T) |
Counts the number of times the specified |
Count<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) |
Counts the number of times |
EndsWith<T>(ReadOnlySpan<T>, T) |
Determines whether the specified value appears at the end of the span. |
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) |
Searches for the specified value and returns the index of its first occurrence. Values are compared using IEquatable{T}.Equals(T). |
IndexOf<T>(ReadOnlySpan<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>(ReadOnlySpan<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>(ReadOnlySpan<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>(ReadOnlySpan<T>, SearchValues<T>) |
Searches for the first index of any of the specified values. |
IndexOfAny<T>(ReadOnlySpan<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>(ReadOnlySpan<T>, T, T, T) |
Searches for the first index of any value other than the specified |
IndexOfAnyExcept<T>(ReadOnlySpan<T>, T, T) |
Searches for the first index of any value other than the specified |
IndexOfAnyExcept<T>(ReadOnlySpan<T>, T) |
Searches for the first index of any value other than the specified |
IndexOfAnyExcept<T>(ReadOnlySpan<T>, SearchValues<T>) |
Searches for the first index of any value other than the specified |
IndexOfAnyExcept<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) |
Searches for the first index of any value other than the specified |
IndexOfAnyExceptInRange<T>(ReadOnlySpan<T>, T, T) |
Searches for the first index of any value outside of the range between |
IndexOfAnyInRange<T>(ReadOnlySpan<T>, T, T) |
Searches for the first index of any value in the range between |
LastIndexOf<T>(ReadOnlySpan<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>(ReadOnlySpan<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>(ReadOnlySpan<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>(ReadOnlySpan<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>(ReadOnlySpan<T>, SearchValues<T>) |
Searches for the last index of any of the specified values. |
LastIndexOfAny<T>(ReadOnlySpan<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>(ReadOnlySpan<T>, T, T, T) |
Searches for the last index of any value other than the specified |
LastIndexOfAnyExcept<T>(ReadOnlySpan<T>, T, T) |
Searches for the last index of any value other than the specified |
LastIndexOfAnyExcept<T>(ReadOnlySpan<T>, T) |
Searches for the last index of any value other than the specified |
LastIndexOfAnyExcept<T>(ReadOnlySpan<T>, SearchValues<T>) |
Searches for the last index of any value other than the specified |
LastIndexOfAnyExcept<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) |
Searches for the last index of any value other than the specified |
LastIndexOfAnyExceptInRange<T>(ReadOnlySpan<T>, T, T) |
Searches for the last index of any value outside of the range between |
LastIndexOfAnyInRange<T>(ReadOnlySpan<T>, T, T) |
Searches for the last index of any value in the range between |
Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>, Int32) |
Determines whether two read-only sequences overlap in memory and outputs the element offset. |
Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) |
Determines whether two read-only sequences overlap in memory. |
Replace<T>(ReadOnlySpan<T>, Span<T>, T, T) |
Copies |
SequenceCompareTo<T>(ReadOnlySpan<T>, ReadOnlySpan<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>, IEqualityComparer<T>) |
Determines whether two sequences are equal by comparing the elements using an IEqualityComparer<T>. |
SequenceEqual<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) |
Determines whether two read-only sequences are equal by comparing the elements using IEquatable{T}.Equals(T). |
Split<T>(ReadOnlySpan<T>, T) | |
Split<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) | |
SplitAny<T>(ReadOnlySpan<T>, SearchValues<T>) | |
SplitAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) | |
StartsWith<T>(ReadOnlySpan<T>, T) |
Determines whether the specified value appears at the start of the span. |
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) |
Removes all leading and trailing occurrences of a specified element from a read-only span. |
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) |
Removes all trailing occurrences of a specified element from a read-only span. |
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) |
Removes all leading occurrences of a specified element from the span. |
TrimStart<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) |
Removes all leading occurrences of a set of elements specified in a read-only span from the span. |