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

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>.

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.

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

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

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

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>.

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

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)

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)

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

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)

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

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

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)

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

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

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

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.

Applies to