Edit

Share via


Span<T> Constructors

Definition

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 T elements starting at a specified memory address.

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)

Source:
Span.cs
Source:
Span.cs
Source:
Span.cs

Creates a new Span<T> of length 1 around the specified reference.

public:
 Span(T % reference);
public Span (ref T reference);
new Span<'T> : 'T -> Span<'T>
Public Sub New (ByRef reference As T)

Parameters

reference
T

A reference to data.

Applies to

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.

length
Int32

The number of T elements to be included in the Span<T>.

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

start
Int32

The zero-based index of the first element to include in the new Span<T>.

length
Int32

The number of elements to include in the new Span<T>.

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