Share via


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)

Syntax

'Declaration
Public Shared Function CreateInstance ( _
    elementType As Type, _
    length As Integer _
) As Array
public static Array CreateInstance(
    Type elementType,
    int length
)
public:
static Array^ CreateInstance(
    Type^ elementType, 
    int length
)
static member CreateInstance : 
        elementType:Type * 
        length:int -> Array 
public static function CreateInstance(
    elementType : Type, 
    length : int
) : Array

Parameters

Return Value

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

Exceptions

Exception Condition
ArgumentNullException

elementType is null Nothing nullptr unit a 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.

Remarks

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

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

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

.NET Framework Security

See Also

Reference

Array Class

System Namespace