New Keyword


New Keyword

Syntax

     New type[(arglist)] 


type (required; any)

The data type of the newly created object.


arglist (optional; any)

A list of comma-delimited parameters sent to the constructor type. If using a default constructor that has no parameters, arglist can be left off completely.

Description

The New keyword creates a new instance of type. The New keyword is often used in assignment statements or to create a new onetime instance to pass as a parameter to a function.

     someVariable = New InterestingClass 

New instances of objects are also created as part of the Dim statement syntax. See the Dim Statement entry in this chapter for additional information.

A completely different use of the New keyword is in the building of constructors. If you create a class Sub procedure and give it the name New, it becomes a class constructor.

Usage at a Glance

  • The New keyword is only used with reference types.

  • A type's constructor is called when you use the New keyword on a declaration. You may include constructor parameters after type. If no parameters are supplied, the default parameterless constructor is used.

See Also

Dim Statement, Sub Statement




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net