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