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