VB.Net - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

VB.Net Variables

VB.Net Variables

shape Description

In the computer language variable can be defined as memory locations. Variable is a name which is given to the storage space where the user can store the data. The variable has a datatype which determines the specific type of data. There are two types of data types in any.Net languages.Declaration of the variable depends upon the user input. If the user has to give the numeric inputs, then user have to declare a variable as an integer.Always the variable declaration will start with the keyword called "Dim" which have different meanings like "Declare in Memory" and "Dimension". VB.Net also support value types like enum and reference type like Class.

shape Conceptual figure

Following is a conceptual figure which describes what are the types of variables?

shape Syntax

[vbnet]Dim VariableName as Datatype[/vbnet] Example: [vbnet]Dim n as integer n=10 'initialization[/vbnet]

Initialization of the Variable

shape Description

The declaration of variable is same in all the languages that in two ways developer can declare the variable where both will have different functionalities. Following is an example to declare the variable. [vbnet]Dim a as integer = 10 'At the time of the declaration&nbsp; <pre>Dim a as integer a=10 ' After the Declaration[/vbnet]

shape Example

Following is a basic example to declare a variable. [vbnet]Imports System </pre> <pre>Public Class Example Shared Sub Main() Dim a As Long Dim b As Integer Dim c As Double a = 10 b = 20 c = a * b Console.WriteLine("a = {0}", a) Console.WriteLine("b = {0}", b) Console.WriteLine("c = {0}", c) Console.ReadLine() End Sub End Class [/vbnet] Output: when user execute the above code, then you will get the following output.

Summary

shape Points

  • Before declaring variable datatype should be declared.
  • Most of the developers will use run time declarations.
  • Dim Variable Name as Datatype is the declaration syntax of variable.