Intrinsic Data Types and the New Keyword

All intrinsic data types support what is known as a default constructor (see Chapter 5). In a nutshell, this feature allows you to create a variable using the New keyword, which automatically sets the variable to its default value. Although it is more cumbersome to use the New keyword when creating a basic data type variable, the following is syntactically well-formed VB 2008 code:

' When you create a basic data type with New, ' it is automatically set to its default value.

Dim b1 As New Boolean() ' b1 automatically set to False.

On a related note, you could also declare an intrinsic data type variable using the full type name through either of these approaches:

' These statements are also functionally identical.

Dim b2 As System.Boolean = New System.Boolean() Dim b3 As System.Boolean

Of course, the chances that you will define a simple Boolean using the full type name or the New keyword in your code is slim to none. It is important, however, to always remember that the VB 2008 keywords for simple data types are little more than a shorthand notation for real types in the System namespace.

Was this article helpful?

0 0

Post a comment