Determining Constant and Variable Scope

Constants, variables, and arrays are extremely useful ways to store and retrieve data in Visual C# .NET code. Hardly a program is written that doesn't use at least one of these elements. To properly use them, however, it's critical that you understand scope.

You had your first encounter with scope in Hour 10, “Creating and Calling Methods,” with the keywords private and public. You learned that code is written in procedures and that procedures are stored in modules. Scope refers to the level that a constant, a variable, an array, or a procedure can be “seen” in code. For a constant or variable, scope can be one of the following levels:

  • Block

  • Method (local)

  • Private

Scope has the same affect on array variables ...

Get Sams Teach Yourself Microsoft® Visual C#™ .NET in 24 Hours now with O’Reilly online learning.

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