ReadOnlySpan<T> Constructors
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.
Overloads
| ReadOnlySpan<T>(T) |
Creates a new ReadOnlySpan<T> of length 1 around the specified reference. |
| 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 |
| 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)
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
Creates a new ReadOnlySpan<T> of length 1 around the specified reference.
public:
ReadOnlySpan(T % reference);
public ReadOnlySpan(ref T reference);
public ReadOnlySpan(in T reference);
new ReadOnlySpan<'T> : 'T -> ReadOnlySpan<'T>
Public Sub New (ByRef reference As T)
Parameters
- reference
- T
A reference to data.
Applies to
ReadOnlySpan<T>(T[])
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
Creates a new ReadOnlySpan<T> over the entirety of a specified array.
public:
ReadOnlySpan(cli::array <T> ^ array);
public ReadOnlySpan(T[]? array);
public ReadOnlySpan(T[] array);
new ReadOnlySpan<'T> : 'T[] -> ReadOnlySpan<'T>
Public Sub New (array As T())
Parameters
- array
- T[]
The array from which to create the ReadOnlySpan<T>.
Remarks
If the array is null, this constructor returns a default ReadOnlySpan<T>.
Applies to
ReadOnlySpan<T>(Void*, Int32)
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
Important
This API is not CLS-compliant.
Creates a new ReadOnlySpan<T> from a specified number of T elements starting at a specified memory address.
public:
ReadOnlySpan(void* pointer, int length);
[System.CLSCompliant(false)]
public ReadOnlySpan(void* pointer, int length);
[<System.CLSCompliant(false)>]
new ReadOnlySpan<'T> : nativeptr<unit> * int -> ReadOnlySpan<'T>
Parameters
- pointer
- Void*
A pointer to the starting address of a specified number of T elements in memory.
- length
- Int32
The number of T elements to be included in the ReadOnlySpan<T>.
- Attributes
Exceptions
T is a reference type or contains references and therefore cannot be stored in unmanaged memory.
length is negative.
Remarks
This constructor should be used with care, since it creates arbitrarily typed Ts from a void*-typed block of memory, and neither pointer nor length are validated by the constructor.
Applies to
ReadOnlySpan<T>(T[], Int32, Int32)
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
- Source:
- ReadOnlySpan.cs
Creates a new ReadOnlySpan<T> that includes a specified number of elements of an array starting at a specified index.
public:
ReadOnlySpan(cli::array <T> ^ array, int start, int length);
public ReadOnlySpan(T[]? array, int start, int length);
public ReadOnlySpan(T[] array, int start, int length);
new ReadOnlySpan<'T> : 'T[] * int * int -> ReadOnlySpan<'T>
Public Sub New (array As T(), start As Integer, length As Integer)
Parameters
- array
- T[]
The array from which to create the ReadOnlySpan<T>.
- start
- Int32
The zero-based index of the first element to include.
- length
- Int32
The number of elements to include.
Exceptions
array is null, but start or length is non-zero.
-or-
start is outside the bounds of the array.
-or-
start and length exceeds the number of elements in the array.
Remarks
If the array is null, this constructor returns a default ReadOnlySpan<T>.