ReadOnlySpan<T> Struct
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)
- T
The type of items in the ReadOnlySpan<T>.
- Inheritance
- Attributes
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.
Read |
Creates a new ReadOnlySpan<T> of length 1 around the specified reference. |
Read |
Creates a new ReadOnlySpan<T> that includes a specified number of elements of an array starting at a specified index. |
Read |
Creates a new ReadOnlySpan<T> over the entirety of a specified array. |
Read |
Creates a new ReadOnlySpan<T> from a specified number of |
Empty |
Returns an empty ReadOnlySpan<T>. |
Is |
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. |
Cast |
Casts a read-only span of |
Copy |
Copies the contents of this ReadOnlySpan<T> into a destination Span<T>. |
Equals(Object) |
Obsolete.
Obsolete.
Not supported. Throws a NotSupportedException. |
Get |
Returns an enumerator for this ReadOnlySpan<T>. |
Get |
Obsolete.
Not supported. Throws a NotSupportedException. |
Get |
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. |
To |
Copies the contents of this read-only span into a new array. |
To |
Returns the string representation of this ReadOnlySpan<T>. |
Try |
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. |
Equality(Read |
Returns a value that indicates whether two ReadOnlySpan<T> instances are equal. |
Implicit(Array |
Defines an implicit conversion of an ArraySegment<T> to a ReadOnlySpan<T>. |
Implicit(T[] to Read |
Defines an implicit conversion of an array to a ReadOnlySpan<T>. |
Inequality(Read |
Returns a value that indicates whether two ReadOnlySpan<T> instances are not equal. |
To |
Produce an immutable array of contents from specified elements. |
Binary |
Searches an entire sorted ReadOnlySpan<T> for a value using the specified IComparable<T> generic interface. |
Binary |
Searches an entire sorted ReadOnlySpan<T> for a specified value using the specified |
Binary |
Searches an entire sorted ReadOnlySpan<T> for a value using the specified |
Common |
Determines the length of any common prefix shared between |
Common |
Finds the length of any common prefix shared between |
Contains<T>(Read |
Indicates whether a specified value is found in a read-only span. Values are compared using IEquatable{T}.Equals(T). |
Contains |
Searches for an occurrence of |
Contains |
Searches for an occurrence of |
Contains |
Searches for an occurrence of any of the specified |
Contains |
Searches for an occurrence of any of the specified |
Contains |
Searches for any value other than |
Contains |
Searches for any value other than |
Contains |
Searches for any value other than the specified |
Contains |
Searches for any value other than the specified |
Contains |
Searches for any value other than the specified |
Contains |
Searches for any value outside of the range between |
Contains |
Searches for any value in the range between |
Count<T>(Read |
Counts the number of times the specified |
Count<T>(Read |
Counts the number of times |
Ends |
Determines whether the specified value appears at the end of the span. |
Ends |
Determines whether the specified sequence appears at the end of a read-only span. |
Index |
Searches for the specified value and returns the index of its first occurrence. Values are compared using IEquatable{T}.Equals(T). |
Index |
Searches for the specified sequence and returns the index of its first occurrence. Values are compared using IEquatable{T}.Equals(T). |
Index |
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. |
Index |
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. |
Index |
Searches for the first index of any of the specified values. |
Index |
Searches for the first index of any of the specified values similar to calling IndexOf several times with the logical OR operator. |
Index |
Searches for the first index of any value other than the specified |
Index |
Searches for the first index of any value other than the specified |
Index |
Searches for the first index of any value other than the specified |
Index |
Searches for the first index of any value other than the specified |
Index |
Searches for the first index of any value other than the specified |
Index |
Searches for the first index of any value outside of the range between |
Index |
Searches for the first index of any value in the range between |
Last |
Searches for the specified value and returns the index of its last occurrence. Values are compared using IEquatable{T}.Equals(T). |
Last |
Searches for the specified sequence and returns the index of its last occurrence. Values are compared using IEquatable{T}.Equals(T). |
Last |
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. |
Last |
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. |
Last |
Searches for the last index of any of the specified values. |
Last |
Searches for the last index of any of the specified values similar to calling LastIndexOf several times with the logical OR operator. |
Last |
Searches for the last index of any value other than the specified |
Last |
Searches for the last index of any value other than the specified |
Last |
Searches for the last index of any value other than the specified |
Last |
Searches for the last index of any value other than the specified |
Last |
Searches for the last index of any value other than the specified |
Last |
Searches for the last index of any value outside of the range between |
Last |
Searches for the last index of any value in the range between |
Overlaps<T>(Read |
Determines whether two read-only sequences overlap in memory and outputs the element offset. |
Overlaps<T>(Read |
Determines whether two read-only sequences overlap in memory. |
Replace<T>(Read |
Copies |
Sequence |
Determines the relative order of two read-only sequences by comparing their elements using IComparable{T}.CompareTo(T). |
Sequence |
Determines whether two sequences are equal by comparing the elements using an IEqualityComparer<T>. |
Sequence |
Determines whether two read-only sequences are equal by comparing the elements using IEquatable{T}.Equals(T). |
Split<T>(Read |
Returns a type that allows for enumeration of each element within a split span using the provided separator character. |
Split<T>(Read |
Returns a type that allows for enumeration of each element within a split span using the provided separator span. |
Split |
Returns a type that allows for enumeration of each element within a split span using the provided separator characters. |
Split |
Returns a type that allows for enumeration of each element within a split span using any of the provided elements. |
Starts |
Determines whether the specified value appears at the start of the span. |
Starts |
Determines whether a specified sequence appears at the start of a read-only span. |
Trim<T>(Read |
Removes all leading and trailing occurrences of a specified element from a read-only span. |
Trim<T>(Read |
Removes all leading and trailing occurrences of a set of elements specified in a read-only span from a read-only span. |
Trim |
Removes all trailing occurrences of a specified element from a read-only span. |
Trim |
Removes all trailing occurrences of a set of elements specified in a read-only span from a read-only span. |
Trim |
Removes all leading occurrences of a specified element from the span. |
Trim |
Removes all leading occurrences of a set of elements specified in a read-only span from the span. |
Product | Versions |
---|---|
.NET | Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided) |
.NET Standard | 2.0 (package-provided), 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: