<PackageReference Include="System.Memory" Version="4.6.0" />

ReadOnlySpan<T>

public struct ReadOnlySpan<T>
ReadOnlySpan represents a contiguous region of arbitrary memory. Unlike arrays, it can point to either managed or native memory, or to memory allocated on the stack. It is type- and memory-safe.
public struct Enumerator<T>

Enumerates the elements of a ReadOnlySpan<T>.

public static ReadOnlySpan<T> Empty { get; }

Returns a 0-length read-only span whose base is the null pointer.

public bool IsEmpty { get; }

Returns true if Length is 0.

public T& modreq(System.Runtime.InteropServices.InAttribute) this[int index] { get; }

Returns the specified element of the read-only span.

public int Length { get; }

The number of items in the read-only span.

public ReadOnlySpan(T[] array)

Creates a new read-only span over the entirety of the target array.

public ReadOnlySpan(T[] array, int start, int length)

Creates a new read-only span over the portion of the target array beginning at 'start' index and ending at 'end' index (exclusive).

public ReadOnlySpan(Void* pointer, int length)

Creates a new read-only span over the target unmanaged buffer. Clearly this is quite dangerous, because we are creating arbitrarily typed T's out of a void*-typed block of memory. And the length is not checked. But if this creation is correct, then all subsequent uses are correct.

public static bool op_Equality(ReadOnlySpan<T> left, ReadOnlySpan<T> right)

Returns true if left and right point at the same memory and have the same length. Note that this does *not* check to see if the *contents* are equal.

public static ReadOnlySpan<T> op_Implicit(T[] array)

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

public static ReadOnlySpan<T> op_Implicit(ArraySegment<T> segment)

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

public static bool op_Inequality(ReadOnlySpan<T> left, ReadOnlySpan<T> right)

Returns false if left and right point at the same memory and have the same length. Note that this does *not* check to see if the *contents* are equal.

public void CopyTo(Span<T> destination)

Copies the contents of this read-only span into destination span. If the source and destinations overlap, this method behaves as if the original values in a temporary location before the destination is overwritten. The span to copy items into.Thrown when the destination Span is shorter than the source Span.

Gets an enumerator for this span.

public T& modreq(System.Runtime.InteropServices.InAttribute) GetPinnableReference()

Returns a reference to the 0th element of the Span. If the Span is empty, returns null reference. It can be used for pinning and is required to support the use of span within a fixed statement.

public ReadOnlySpan<T> Slice(int start)

Forms a slice out of the given read-only span, beginning at 'start'.

public ReadOnlySpan<T> Slice(int start, int length)

Forms a slice out of the given read-only span, beginning at 'start', of given length

public T[] ToArray()

Copies the contents of this read-only span into a new array. This heap allocates, so should generally be avoided, however it is sometimes necessary to bridge the gap with APIs written in terms of arrays.

public bool TryCopyTo(Span<T> destination)

Copies the contents of this read-only span into destination span. If the source and destinations overlap, this method behaves as if the original values in a temporary location before the destination is overwritten. If the destination span is shorter than the source span, this method return false and no data is written to the destination.