Instantiating Classes with New

To create an object that is an instance of a class, you use the keyword New. Internally, the .NET Framework automatically appropriates sufficient memory for storing the field values[10]. An object variable declared with the same type as the class is used to access elements of the class instance. So for example, you create an object of the Contact class by using the following statements:

Dim adr As Contact
adr = New Contact

The first line of code creates an object variable of type Contact, and the second assigns a new instance. You can also combine both lines into one, as demonstrated in the following:

Dim adr As New Contact

Then you can use the class instance with the help of the defined object variables to access the ...

Get Microsoft® Visual Basic® 2010 Developer’s Handbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.