CreateInstance Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

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

public static Array CreateInstance(
	Type elementType,
	int length
)

Parameters

elementType
Type: System..::..Type
The Type of the Array to create.
length
Type: System..::..Int32
The size of the Array to create.

Return Value

Type: System..::..Array
A new one-dimensional Array of the specified Type with the specified length, using zero-based indexing.

ExceptionCondition
ArgumentNullException

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

ArgumentException

elementType is not a valid Type.

NotSupportedException

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

-or-

elementType is an open generic type.

ArgumentOutOfRangeException

length is less than zero.

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

Reference-type elements are initialized to nullNothingnullptrunita null reference (Nothing in Visual Basic). Value-type elements are initialized to zero.

This method is an O(n) operation, where n is length.

Show: