New
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

New

The New keyword introduces a New clause, which creates a new object instance. The New clause must specify a defined class from which the instance can be created. You can use New in a declaration statement or an assignment statement. When the statement is executed, it calls the constructor of the specified class, passing any arguments you have supplied:

Dim Obj As Object
Obj = New SomeClass("String required by constructor")
' ...
Dim MyLabel As New Label()

Since arrays are classes, New can create a new array instance:

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

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

The New keyword is used in this context:

Dim Statement

See Also

Visual Basic Language Keywords | Object Lifetime: How Objects Are Created and Destroyed | Using Constructors and Destructors | OutOfMemoryException Class

Show:
© 2016 Microsoft