Wednesday, 19 March 2014

Variable Initialization in VB.Net

Variables are initialized (assigned a value) with an equal sign followed by a constant expression. The general form of initialization is:

variable_name = value;
 
for example,

Dim pi As Double
pi = 3.14159
 
You can initialize a variable at the time of declaration as follows:

Dim StudentID As Integer = 100
Dim StudentName As String = "Bill Smith"

Example

Try the following example, which makes use of various types of variables:


Module variablesNdataypes
   Sub Main()
      Dim a As Short
      Dim b As Integer
      Dim c As Double
      a = 10
      b = 20
      c = a + b
      Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c)
      Console.ReadLine()
   End Sub
End Module
 
When the above code is compiled and executed, it produces the following result:

a = 10, b = 20, c = 30
 
 
Source : http://www.tutorialspoint.com 

No comments:

Post a Comment