Types Of Variable


In c sharp we have normally 3 types of variables
a) Instance Variables   b) Static Variables   c) Local Variables

I saved my program on the path :- C:\Users\seven\Desktop\TypesOfVariable.cs

-------------------------------------------------------------
using System;

class TypesOfVariable
{
int a;                            //Instance variable.
static int b;                  //Static variable.
public static void Main()
{
int c;                          //Local variable.

TypesOfVariable tov = new TypesOfVariable();
tov.a = 10;
b = 20;
c = 30;

Console.WriteLine("The value of a is " + tov.a);
Console.WriteLine("The value of b is " + b);
Console.WriteLine("The value of c is " + c);

}
}
-------------------------------------------------------------------



You notice that in the Class name TypesOfVariable we use 3 type of variables :

Local variable always declared and used within the method.
Static variable always declared within the class and used in the methods.
Instance variable always declared within the class and used in the methods but we need object of that class in which they are declared, but the important thing is that, if method is static the we need an object if it is non-static method(instance method) then we simply assign the value of the variable and use it.

Types Of Variable Types Of Variable Reviewed by Baljeet Singh on 00:55 Rating: 5

No comments:

Powered by Blogger.