O'Reilly logo

C# Primer Plus by Klaus Michelsen

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

The Scope of Variables

The majority of the source code presented in the previous chapters has mainly used the block construct and its accompanying matching braces to mark out the context of a class or to delineate the context of methods, the Main() method in particular.

With the introduction of if-else statements and their ability to contain blocks of code (compound statements), you will begin to create programs containing several layers of nested blocks inside and next to each other. It is, therefore, important to introduce a new concept closely related to the block construct called scope. The scope determines which segments (and hence variables) of the source code are visible (and hence accessible) to other parts of the source code. Scope is ...

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