Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

New (Visual Basic) 

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

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft