Op Englesch liesen Editéieren

Deelen iwwer


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.

C#
public Span(ref T reference);

Parameters

reference
T

A reference to data.

Applies to

.NET 10 an aner Versiounen
Produkt Versiounen
.NET 7, 8, 9, 10

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.

C#
public Span(T[]? array);
C#
public Span(T[] array);

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

.NET 10 an aner Versiounen
Produkt Versiounen
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1

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.

C#
[System.CLSCompliant(false)]
public Span(void* pointer, int length);

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

.NET 10 an aner Versiounen
Produkt Versiounen
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1

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.

C#
public Span(T[]? array, int start, int length);
C#
public Span(T[] array, int start, int length);

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

.NET 10 an aner Versiounen
Produkt Versiounen
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1