System Data Types and VB Shorthand Notation

Like any programming language, VB defines an intrinsic set of data types, which are used to represent local variables, member variables, return values, and input parameters. Although many of the VB data types are named identically to data types found under VB6, be aware that there is not a direct mapping (especially in terms of a data type's maximum and minimum range).

Note The Ulnteger, ULong, and SByte data types are notCLS compliant (see Chapters 1 and 16 for details on CLS compliance). Therefore, if you expose these data types from an assembly, you cannot guarantee that every .NET programming language will be able to process this data.

The most significant change from VB6 is that the data type keywords of Visual Basic 2008 are actually shorthand notations for full-blown types in the System namespace. Table 3-4 documents the data types of VB 2008 (with the size of storage allocation), the System data type equivalents, and the range of each type.

Table 3-4. The Intrinsic Data Types of VB 2008

VB Keyword

CLS Compliant?

System Type

Range

Meaning in Life

Boolean

Yes

System.Boolean

True or False

Represents truth or falsity

SByte

No

System.SByte

-128 to 127

Signed 8-bit number

Byte

Yes

System.Byte

0 to 255

Unsigned 8-bit number

Short

Yes

System.Int16

-32,768 to 32,767

Signed 16-bit number

UShort

No

System.UInt16

0 to 65,535

Unsigned 16-bit number

Integer

Yes

System.Int32

-2,147,483,648 to 2,147,483,647

Signed 32-bit number

Ulnteger

No

System.UInt32

0 to 4,294,967,295

Unsigned 32-bit number

Long

Yes

System.Int64

-9,223,372,036,854,775,808 to

Signed 64-bit number

9,223,372,036,854,775,807

Continued

9,223,372,036,854,775,807

Continued

Table 3-4. Continued

VB Keyword

CLS Compliant?

System Type

Range

Meaning in Life

ULong

No

System,

,UInt64

0 to 18,446,744,073,709,551,615

Unsigned 64-bit number

Char

Yes

System,

.Char

U+0000 to U+ffff

A single 16-bit Unicode character

Single

Yes

System,

.Single

±1.5 X 1045 to ±3.4 X 1038

32-bit floating-point number

Double

Yes

System,

.Double

±5.0 X 10324 to ±1.7 X 10308

64-bit floating-point number

Decimal

Yes

System,

.Decimal

±1.0 X 10e28 to ±7.9 X 10e28

A 96-bit signed number

String

Yes

System

.String

Limited by system memory

Represents a set of Unicode characters

Date

Yes

System

.DateTime

January 1, 0001 to December 31, 9999

Represents a time/date value

Object

Yes

System

.Object

Any type can be stored in an object variable

The base class of all types in the .NET universe

Each of the numerical types (Short, Integer, and so forth) as well as the Date type map to a corresponding structure in the System namespace. In a nutshell, structures are "value types" allocated on the stack. On the other hand, String and Object are "reference types," meaning the variable is allocated on the managed heap. You will examine full details of value and reference types in Chapter 12; however, for the time being, simply understand that value types can be allocated into memory quickly and have a very fixed and predictable lifetime.

Was this article helpful?

0 0

Post a comment