Scope and Visibility

When discussing scope, this section refers to the parts of a program where an identifier refers to a specific declaration. Visibility refers to whether an identifier can be seen by other program elements. Now let's look at how these concepts are implemented in C#.

Besides required blocks, it's possible to place blocks within code, independent of supporting other language constructs. This could be useful if there was an iterative or recursive routine with local variables that weren't necessary for subsequent iterations or recursive calls. By isolating these variables and the data working on them within a block, a local scope can be established where those data items only exist within the scope of that block and aren't carried ...

Get C# Unleashed 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.