New (Visual Basic) 

Introduces a New clause to create a new object instance, or specifies a constructor constraint on a type parameter.

Remarks

In a type parameter list, a New constraint specifies that the supplied type must expose an accessible parameterless constructor. For more information on type parameters and constraints, see Type List.

In a declaration or assignment statement, a New clause must specify a defined class from which the instance can be created. This means the class must expose a constructor that the calling code can access.

You can use a New clause in a declaration statement or an assignment statement. When the statement runs, it calls the constructor of the specified class, passing any arguments you have supplied. The following example demonstrates this.

Dim someObj As Object
someObj = New someClass("String required by constructor")
Dim nextLabel As New Label()

Since arrays are classes, New can create a new array instance, as shown in the following example.

Dim intArray As Integer()
intArray = New Integer() {0, 1, 2, 3}

The common language runtime (CLR) throws an OutOfMemoryException error if there is insufficient memory to create the new instance.

The New keyword can be used in these contexts:

Dim Statement (Visual Basic)

Of

See Also

Reference

Visual Basic Language Keywords
Type List
Using Constructors and Destructors
OutOfMemoryException

Concepts

Generic Types in Visual Basic
Object Lifetime: How Objects Are Created and Destroyed