Array.CreateInstance Method (Type, Int64[])

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

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

static member CreateInstance : 
        elementType:Type * 
        lengths:int64[] -> Array 

Parameters

elementType
Type: System.Type
The Type of the Array to create.
lengths
Type: System.Int64[]
An array of 64-bit integers that represent the size of each dimension of the Array to create. Each integer in the array must be between zero and Int32.MaxValue, inclusive.

Return Value

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

ExceptionCondition
ArgumentNullException

elementType is a null reference (Nothing in Visual Basic).

-or-

lengths is a null reference (Nothing in Visual Basic).

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 or greater than Int32.MaxValue.

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 a null reference (Nothing in Visual Basic). 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.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft