Scoping in C#. : Variable Scope « Language Basics « C# / C Sharp






Scoping in C#.

 


using System;

class MainClass {
    // Class level x variable
    static int x = 10;

    public static void Main() {
        // Locally defined copy of x
        int x = 5;
        int y = x;
        double z = y + 10.25;

        int a = (int)z;

        Console.WriteLine("X = {0} Y = {1} Z = {2}", x, y, z);
        Console.WriteLine("A = {0}", a);

        Console.WriteLine("Class Level X = {0}", MainClass.x);
    }
}

 








Related examples in the same category

1.Class level Variable scopeClass level Variable scope
2.Scope class demonstrates instance and local variable scopes.Scope class demonstrates instance and local variable scopes.
3.method scope variable
4.System maximums and minimums.