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

Definition

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)
Type Parameters
T

The type of items in the ReadOnlySpan<T>.

Inheritance
ReadOnlySpan<T>ReadOnlySpan<T>ReadOnlySpan<T>ReadOnlySpan<T>

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[]) ReadOnlySpan<T>(T[]) ReadOnlySpan<T>(T[]) ReadOnlySpan<T>(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)

Creates a new ReadOnlySpan<T> from a specified number of bytes starting at a specified memory address.

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

Creates a new ReadOnlySpan<T> from an array starting at the specified index and continuing until the end of the array.

ReadOnlySpan<T>(T[], Int32, Int32) ReadOnlySpan<T>(T[], Int32, Int32) ReadOnlySpan<T>(T[], Int32, Int32) 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.

Properties

Empty Empty Empty Empty

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.

Methods

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

Copies the contents of this ReadOnlySpan<T> into a destination Span<T>.

DangerousCreate(Object, T, Int32) DangerousCreate(Object, T, Int32) DangerousCreate(Object, T, Int32) DangerousCreate(Object, T, Int32)

Creates a new ReadOnlySpan<T> over a portion of a regular managed object.

DangerousGetPinnableReference() DangerousGetPinnableReference() DangerousGetPinnableReference() DangerousGetPinnableReference()

Returns a reference to the element of the ReadOnlySpan<T> at index zero. If the read-only span is empty, returns the reference to the memory location where the first element would have been stored.

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

Not supported. Throws a NotSupportedException.

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

Returns an enumerator for this ReadOnlySpan<T>.

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

Not supported. Throws a NotSupportedException.

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()

Returns the string representation of this ReadOnlySpan<T>.

TryCopyTo(Span<T>) TryCopyTo(Span<T>) TryCopyTo(Span<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>) Equality(ReadOnlySpan<T>, ReadOnlySpan<T>) Equality(ReadOnlySpan<T>, ReadOnlySpan<T>) Equality(ReadOnlySpan<T>, ReadOnlySpan<T>)

Returns a value that indicates whether two ReadOnlySpan<T> instances are equal.

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

Defines an implicit conversion of an array to a ReadOnlySpan<T>.

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

Defines an implicit conversion of an ArraySegment<T> to a ReadOnlySpan<T>.

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

Returns a value that indicates whether two ReadOnlySpan<T> instances are not equal.

Extension Methods

BinarySearch<T>(ReadOnlySpan<T>, IComparable<T>) BinarySearch<T>(ReadOnlySpan<T>, IComparable<T>) BinarySearch<T>(ReadOnlySpan<T>, IComparable<T>) BinarySearch<T>(ReadOnlySpan<T>, IComparable<T>)
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)
BinarySearch<T,TComparable>(ReadOnlySpan<T>, TComparable) BinarySearch<T,TComparable>(ReadOnlySpan<T>, TComparable) BinarySearch<T,TComparable>(ReadOnlySpan<T>, TComparable) BinarySearch<T,TComparable>(ReadOnlySpan<T>, TComparable)
CompareTo(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) CompareTo(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) CompareTo(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) CompareTo(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison)
Contains(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) Contains(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) Contains(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) Contains(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison)
EndsWith(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) EndsWith(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) EndsWith(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) EndsWith(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison)
EndsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) EndsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) EndsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) EndsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
Equals(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) Equals(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) Equals(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) Equals(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison)
IndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) IndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) IndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) IndexOf(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison)
IndexOf<T>(ReadOnlySpan<T>, T) IndexOf<T>(ReadOnlySpan<T>, T) IndexOf<T>(ReadOnlySpan<T>, T) IndexOf<T>(ReadOnlySpan<T>, 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>)
IndexOfAny<T>(ReadOnlySpan<T>, T, 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, T) 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>, ReadOnlySpan<T>) IndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) IndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) IndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
IsWhiteSpace(ReadOnlySpan<Char>) IsWhiteSpace(ReadOnlySpan<Char>) IsWhiteSpace(ReadOnlySpan<Char>) IsWhiteSpace(ReadOnlySpan<Char>)
LastIndexOf<T>(ReadOnlySpan<T>, T) LastIndexOf<T>(ReadOnlySpan<T>, T) LastIndexOf<T>(ReadOnlySpan<T>, T) LastIndexOf<T>(ReadOnlySpan<T>, 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>)
LastIndexOfAny<T>(ReadOnlySpan<T>, T, 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, T) 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>, ReadOnlySpan<T>) LastIndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) LastIndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) LastIndexOfAny<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) Overlaps<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
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)
SequenceCompareTo<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceCompareTo<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceCompareTo<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceCompareTo<T>(ReadOnlySpan<T>, ReadOnlySpan<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>)
StartsWith(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) StartsWith(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) StartsWith(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison) StartsWith(ReadOnlySpan<Char>, ReadOnlySpan<Char>, StringComparison)
StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
ToLower(ReadOnlySpan<Char>, Span<Char>, CultureInfo) ToLower(ReadOnlySpan<Char>, Span<Char>, CultureInfo) ToLower(ReadOnlySpan<Char>, Span<Char>, CultureInfo) ToLower(ReadOnlySpan<Char>, Span<Char>, CultureInfo)
ToLowerInvariant(ReadOnlySpan<Char>, Span<Char>) ToLowerInvariant(ReadOnlySpan<Char>, Span<Char>) ToLowerInvariant(ReadOnlySpan<Char>, Span<Char>) ToLowerInvariant(ReadOnlySpan<Char>, Span<Char>)
ToUpper(ReadOnlySpan<Char>, Span<Char>, CultureInfo) ToUpper(ReadOnlySpan<Char>, Span<Char>, CultureInfo) ToUpper(ReadOnlySpan<Char>, Span<Char>, CultureInfo) ToUpper(ReadOnlySpan<Char>, Span<Char>, CultureInfo)
ToUpperInvariant(ReadOnlySpan<Char>, Span<Char>) ToUpperInvariant(ReadOnlySpan<Char>, Span<Char>) ToUpperInvariant(ReadOnlySpan<Char>, Span<Char>) ToUpperInvariant(ReadOnlySpan<Char>, Span<Char>)
Trim(ReadOnlySpan<Char>) Trim(ReadOnlySpan<Char>) Trim(ReadOnlySpan<Char>) Trim(ReadOnlySpan<Char>)
Trim(ReadOnlySpan<Char>, Char) Trim(ReadOnlySpan<Char>, Char) Trim(ReadOnlySpan<Char>, Char) Trim(ReadOnlySpan<Char>, Char)
Trim(ReadOnlySpan<Char>, ReadOnlySpan<Char>) Trim(ReadOnlySpan<Char>, ReadOnlySpan<Char>) Trim(ReadOnlySpan<Char>, ReadOnlySpan<Char>) Trim(ReadOnlySpan<Char>, ReadOnlySpan<Char>)
TrimEnd(ReadOnlySpan<Char>) TrimEnd(ReadOnlySpan<Char>) TrimEnd(ReadOnlySpan<Char>) TrimEnd(ReadOnlySpan<Char>)
TrimEnd(ReadOnlySpan<Char>, Char) TrimEnd(ReadOnlySpan<Char>, Char) TrimEnd(ReadOnlySpan<Char>, Char) TrimEnd(ReadOnlySpan<Char>, Char)
TrimEnd(ReadOnlySpan<Char>, ReadOnlySpan<Char>) TrimEnd(ReadOnlySpan<Char>, ReadOnlySpan<Char>) TrimEnd(ReadOnlySpan<Char>, ReadOnlySpan<Char>) TrimEnd(ReadOnlySpan<Char>, ReadOnlySpan<Char>)
TrimStart(ReadOnlySpan<Char>) TrimStart(ReadOnlySpan<Char>) TrimStart(ReadOnlySpan<Char>) TrimStart(ReadOnlySpan<Char>)
TrimStart(ReadOnlySpan<Char>, Char) TrimStart(ReadOnlySpan<Char>, Char) TrimStart(ReadOnlySpan<Char>, Char) TrimStart(ReadOnlySpan<Char>, Char)
TrimStart(ReadOnlySpan<Char>, ReadOnlySpan<Char>) TrimStart(ReadOnlySpan<Char>, ReadOnlySpan<Char>) TrimStart(ReadOnlySpan<Char>, ReadOnlySpan<Char>) TrimStart(ReadOnlySpan<Char>, ReadOnlySpan<Char>)
AsBytes<T>(ReadOnlySpan<T>) AsBytes<T>(ReadOnlySpan<T>) AsBytes<T>(ReadOnlySpan<T>) AsBytes<T>(ReadOnlySpan<T>)
IndexOf(ReadOnlySpan<Byte>, Byte) IndexOf(ReadOnlySpan<Byte>, Byte) IndexOf(ReadOnlySpan<Byte>, Byte) IndexOf(ReadOnlySpan<Byte>, Byte)
IndexOf(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) IndexOf(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) IndexOf(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) IndexOf(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>)
IndexOf<T>(ReadOnlySpan<T>, T) IndexOf<T>(ReadOnlySpan<T>, T) IndexOf<T>(ReadOnlySpan<T>, T) IndexOf<T>(ReadOnlySpan<T>, 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>)
IndexOfAny(ReadOnlySpan<Byte>, Byte, Byte) IndexOfAny(ReadOnlySpan<Byte>, Byte, Byte) IndexOfAny(ReadOnlySpan<Byte>, Byte, Byte) IndexOfAny(ReadOnlySpan<Byte>, Byte, Byte)
IndexOfAny(ReadOnlySpan<Byte>, Byte, Byte, Byte) IndexOfAny(ReadOnlySpan<Byte>, Byte, Byte, Byte) IndexOfAny(ReadOnlySpan<Byte>, Byte, Byte, Byte) IndexOfAny(ReadOnlySpan<Byte>, Byte, Byte, Byte)
IndexOfAny(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) IndexOfAny(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) IndexOfAny(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) IndexOfAny(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>)
NonPortableCast<TFrom,TTo>(ReadOnlySpan<TFrom>) NonPortableCast<TFrom,TTo>(ReadOnlySpan<TFrom>) NonPortableCast<TFrom,TTo>(ReadOnlySpan<TFrom>) NonPortableCast<TFrom,TTo>(ReadOnlySpan<TFrom>)
SequenceEqual(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) SequenceEqual(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) SequenceEqual(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) SequenceEqual(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>)
SequenceEqual<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceEqual<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceEqual<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) SequenceEqual<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
StartsWith(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) StartsWith(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) StartsWith(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>) StartsWith(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>)
StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>) StartsWith<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

Applies to