Data Types in Visual Basic .Net

Data types in computer programming language mean what type of data can hold a variable. As in any other programming language in Visual Basic also, when you declare a variable, you have to inform the compiler that which type of data is going to hold the variable.

Syntax for variable declaration in VB.Net

Dim Variable_Name As DataType

Here the keyword Dim is used to declare the variable Variable_Name, which will be declared as the data type DataType.

Examples for variable declaration in VB.Net

Dim a As Integer

Declaring a as integer type data.

Dim s As String

Declaring s as string type data.

Visual Basic .Net supports the following data types:

Boolean:

VB supports the boolean data type which stores only two boolean values; true(1) or false(o).

Byte:

A byte data type stores the values from 0 to 255 with  1-byte storage allocation.

Char:

The char type allocates 2 bytes in memory and can store values from o to 65535.

Date:

A date type is used to declare a variable as a date. It needs 8 bytes to allocate storage.

Decimal:

It stores the values with up to 28 digits after the decimal point. Needs 16 bytes of memory.

Double:

It can hold more range values than integer type, also supports values with decimal points. It needs 8 bytes in memory.

Integer:

An integer type variable can store values ranging from -2,147,483,648 to 2,147,483,647. It needs only 4 bytes for allocation.

Long:

The long type variable can store values ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. The storage space is same as double type.

Object:

If you declare a variable in Object type, it can hold any type of data. An object type variable needs 4 bytes in 32-bit computer and 8 bytes on a 64-bit computer for memory allocation.

String:

A string type data can hold string values which include 0 to 2 billion Unicode characters.

These are the major data types in the Visual Basic .Net.