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