Scope determines the region of program text (that is, lexical scoping) in which it’s valid to refer to a name of some entity without requiring further qualification. Scopes can be nested, too. For example, when declaring a class, a scope is introduced for its members. Some kinds of members, like methods, introduce a new scope:

class ScopeSample{    private int x = 42;    public void InnerScope()    {        int x = 53;        int y = x; // refers to the local variable x        // ...    }    public void OuterScope()    {        int y = x; // refers to the field x        // ...    }}

The InnerScope method in the preceding sample declares a local variable called x, hiding the class’s instance field that’s also ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.