O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Scope

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required