Scope of Variables in C#

Scope of Variable is the region of code within which the variable can be accessed. It depends on the type of the variable and place of its declaration. In C#, there are several types of variables:

  • Static Variables
  • Instance Variables
  • Local Variables
  • Array Elements
  • Value Parameters
  • Reference Parameters
  • Output Parameters
  • class Test
      static int p;
      int n;
      void display(int x, ref int y, out int z, int [] a)
      int q=25;

  • p as a static variable
  • n as an instance variable
  • x as a value parameter
  • y as a reference parameter
  • z as an output parameter
  • a[0] as an array element
  • q as a local variable
  • Recommended Posts:

        1. C# Features
        2. Difference Between C++ and C#
        3. Difference Between C# and Java
        4. .NET Framework
        5. Benefits of .NET
        6. C# Program Structure
        7. C# Command Line Arguments
        8. Console.ReadLine() and Console.WriteLine()
        9. C# Literals
        10. C# Data Types
        11. Scope of Variables in C#
        12. Boxing and Unboxing in C#
        13. C# Operators
        14. C# Type Casting