Čítať v angličtine Upraviť

Zdieľať cez


Array.CreateInstanceFromArrayType Method

Definition

Overloads

CreateInstanceFromArrayType(Type, Int32[])

Creates a multidimensional Array of the specified Type and dimension lengths, with zero-based indexing.

CreateInstanceFromArrayType(Type, Int32)

Creates a one-dimensional Array of the specified array type and length, with zero-based indexing.

CreateInstanceFromArrayType(Type, Int32[], Int32[])

Creates a multidimensional Array of the specified Type and dimension lengths, with the specified lower bounds.

CreateInstanceFromArrayType(Type, Int32[])

Source:
Array.cs

Creates a multidimensional Array of the specified Type and dimension lengths, with zero-based indexing.

C#
public static Array CreateInstanceFromArrayType(Type arrayType, params int[] lengths);

Parameters

arrayType
Type

The type of the array (not of the array element type).

lengths
Int32[]

The dimension lengths, specified in an array of 32-bit integers.

Returns

A new multidimensional Array of the specified Type with the specified length for each dimension, using zero-based indexing.

Exceptions

arrayType is null.

-or-

lengths is null.

Any value in lengths is less than zero.

The lengths array is empty.

-or-

arrayType is not an array type.

-or-

arrayType rank does not match lengths length.

Remarks

When the array type is readily available, this method should be preferred over CreateInstance(Type, Int32[]), as it has better performance and it is AOT-friendly.

Applies to

.NET 10 a .NET 9
Produkt Verzie
.NET 9, 10

CreateInstanceFromArrayType(Type, Int32)

Source:
Array.cs

Creates a one-dimensional Array of the specified array type and length, with zero-based indexing.

C#
public static Array CreateInstanceFromArrayType(Type arrayType, int length);

Parameters

arrayType
Type

The type of the array (not of the array element type).

length
Int32

The size of the Array to create.

Returns

A new one-dimensional Array of the specified Type with the specified length.

Exceptions

arrayType is null.

length is negative.

arrayType is not an array type.

-or-

arrayType is not one-dimensional array.

Remarks

When the array type is readily available, this method should be preferred over CreateInstance(Type, Int32), as it has better performance and it is AOT-friendly.

Applies to

.NET 10 a .NET 9
Produkt Verzie
.NET 9, 10

CreateInstanceFromArrayType(Type, Int32[], Int32[])

Source:
Array.cs

Creates a multidimensional Array of the specified Type and dimension lengths, with the specified lower bounds.

C#
public static Array CreateInstanceFromArrayType(Type arrayType, int[] lengths, int[] lowerBounds);

Parameters

arrayType
Type

The type of the array (not of the array element type).

lengths
Int32[]

The dimension lengths, specified in an array of 32-bit integers.

lowerBounds
Int32[]

A one-dimensional array that contains the lower bound (starting index) of each dimension of the Array to create.

Returns

A new multidimensional Array of the specified Type with the specified length and lower bound for each dimension.

Exceptions

arrayType is null.

-or-

lengths is null.

-or-

lowerBounds is null.

The lengths and lowerBounds arrays do not contain the same number of elements.

-or-

The lengths array is empty.

-or-

arrayType is not an array type.

-or-

arrayType rank does not match lengths length.

Any value in lengths is less than zero.

Native AOT: any value in lowerBounds is different than zero.

Remarks

When the array type is readily available, this method should be preferred over CreateInstance(Type, Int32[], Int32[]), as it has better performance and it is AOT-friendly.

Applies to

.NET 10 a .NET 9
Produkt Verzie
.NET 9, 10