|Numeric (int, float, short, etc.)||0|
Scope of Variables The region of source code over which the definition of a variable is visible is called the scope of a variable. In other words the lifetime of a variable and its accessibility are referred to as scope. In C# a scope is indicated by a square bracket. C# defines several types of variables. These include: · static variables · instance variables · array elements · value parameters · reference parameters · output parameters · local variables. Each of these categories will have a different lifetime or scope. A static variable also known as static field is not part of a specific instance. There is only one copy of the static variable for all instances of a class. These variables are accessible from anywhere in the class in which they are defined. The instance variables are also class level variables but there is separate copy of these variables for every instance of a class. Arrays can be defined inside a class or inside the methods of a class.
Variables defined inside methods are called local variables. They cease to exist when the method gets terminated. In case of passing by value to a method the method’s argument (formal argument) is initialized with a copy of the value (actual argument) from the caller. Any changes that take place inside the method have no affect on the original value of the variable. In case of passing by reference both the actual and formal arguments are referencing to the same memory location. Any changes that take place inside the method will be reflected on the original value of the variable. The out parameter is used only to pass a result back from a method. Any changes made to the parameter in the method will be reflected in that variable when control passes back to the calling method. Two variables with the same name can not defined inside the same scope.