5

example to illustrate :

public class Something
{
    private static int number;

    static Something()
    {
        int number = 10;

        // Syntax to distingish between local variable and static variable ?
    }
}

Inside the static constructor, is there a syntax that can be used to distinguish between the local variable called "number", and the static variable of the same name ?

Merlyn Morgan-Graham
  • 58,163
  • 16
  • 128
  • 183
Moe Sisko
  • 11,665
  • 8
  • 50
  • 80

2 Answers2

8
Something.number

Obvious, no?.

Mark H
  • 13,797
  • 4
  • 31
  • 45
  • 1
    And if your class isn't static, you can be all like: class Something { int number; public Something() { int number = 10; this.number = number + 1; } } – oscilatingcretin Aug 26 '11 at 01:13
3

Unqualified will get you the inner-most scoped variable (the local variable):

Console.WriteLine(number);

10

You can qualify your usage to get the static variable:

Console.WriteLine(Something.number);

0

Merlyn Morgan-Graham
  • 58,163
  • 16
  • 128
  • 183