Array.CreateInstance Method (Type, Int32[])

 

Creates a multidimensional Array of the specified Type and dimension lengths, with zero-based indexing. The dimension lengths are specified in an array of 32-bit integers.

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

static member CreateInstance : 
        elementType:Type *
        [<ParamArrayAttribute>] lengths:int[] -> Array

Parameters

elementType
Type: System.Type

The Type of the Array to create.

lengths
Type: System.Int32[]

An array of 32-bit integers that represent the size 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 for each dimension, using zero-based indexing.

Exception Condition
ArgumentNullException

elementType is null.

-or-

lengths is null.

ArgumentException

elementType is not a valid Type.

-or-

The lengths array contains less than one element.

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.

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

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.

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.

The following code example shows how to create and initialize a multidimensional Array.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: