Popular Posts

Saturday, March 21, 2009

Data Types, Access Specifiers

Data Types in VB .NET

The Data types available in VB .NET, their size, type, description are summarized in the table below.














Data TypeSize in BytesDescriptionType
Byte18-bit unsigned integerSystem.Byte
Char216-bit Unicode charactersSystem.Char
Integer432-bit signed integerSystem.Int32
double864-bit floating point variableSystem.Double
Long864-bit signed integerSystem.Int64
Short216-bit signed integerSystem.Int16
Single432-bit floating point variableSystem.Single
StringvariesNon-Numeric TypeSystem.String
Date8/td>System.Date
Boolean2Non-Numeric TypeSystem.Boolean
Object4Non-Numeric TypeSystem.Object
Decimal16128-bit floating point variableSystem.Decimal


Access Specifiers

Access specifiers let's us specify how a variable, method or a class can be used. The following are the most commonly used one's:

Public: Gives variable public access which means that there is no restriction on their accessibility
Private: Gives variable private access which means that they are accessible only within their declaration content
Protected: Protected access gives a variable accessibility within their own class or a class derived from that class
Friend: Gives variable friend access which means that they are accessible within the program that contains their declaration
Protected Friend: Gives a variable both protected and friend access
Static: Makes a variable static which means that the variable will hold the value even the procedure in which they are declared ends
Shared: Declares a variable that can be shared across many instances and which is not associated with a specific instance of a class or structure
ReadOnly: Makes a variable only to be read and cannot be written

Variables

Variables are used to store data. A variable has a name to which we refer and the data type, the type of data the variable holds. VB .NET now needs variables to be declared before using them. Variables are declared with the Dim keyword. Dim stands for Dimension.

Example

Imports System.Console
Module Module1

Sub Main()
Dim a,b,c as Integer
'declaring three variables of type integer
a=10
b=20
c=a+b
Write("Sum of a and b is" & c)
End Sub

End Module

No comments:

Post a Comment