Array.CreateInstance Method (Type, Int32[], Int32[])

July 28, 2014

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static Array CreateInstance(
	Type elementType,
	int[] lengths,
	int[] lowerBounds
)

Parameters

elementType
Type: System.Type
The Type of the Array to create.
lengths
Type: System.Int32 []
A one-dimensional array that contains the size of each dimension of the Array to create.
lowerBounds
Type: System.Int32 []
A one-dimensional array that contains the lower bound (starting index) of each dimension of the Array to create.

Return Value

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

ExceptionCondition
ArgumentNullException

elementType is null.

-or-

lengths is null.

-or-

lowerBounds is null.

ArgumentException

elementType is not a valid Type.

-or-

The lengths array contains less than one element.

-or-

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

NotSupportedException

elementType is not supported. For example, Void is not supported.

-or-

elementType is an open generic type.

ArgumentOutOfRangeException

Any value in lengths is less than zero.

-or-

Any value in lowerBounds is very large, such that the sum of a dimension's lower bound and length is greater than Int32.MaxValue.

Unlike most classes, Array provides the CreateInstance method, instead of public constructors, to allow for late bound access.

The lengths and lowerBounds arrays must have the same number of elements. The number of elements in the lengths array must equal the number of dimensions in the new Array.

Each element of the lengths array must specify the length of the corresponding dimension in the new Array.

Each element of the lowerBounds array must specify the lower bound of the corresponding dimension in the new Array. Generally, the .NET Framework class library and many programming languages do not handle nonzero lower bounds.

Reference-type elements are initialized to null. Value-type elements are initialized to zero.

This method is an O(n) operation, where n is the product of all values in lengths.

Windows Phone OS

Supported in: 8.1, 8.0

Show:
© 2014 Microsoft