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 ...
Get C# Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.