We're getting to the end of our shallow dive into variables, but there's still one more important topic we need to cover: scope. Similar to access modifiers determining which outside classes can grab a variable's information, variable scope is the term used to describe where a given variable exists and can be accessed within its containing class.
There are three main levels of variable scope in C#:
- Global scope refers to a variable that can be accessed by an entire program, in this case, a game. C# doesn't directly support global variables, but the concept is useful in certain cases, which we'll cover in Chapter 10, Revisiting Types, Methods, and Classes
- Class or member scope refers to a variable that is accessible anywhere in its containing class.
- Local scope refers to a variable that is only accessible inside the specific block of code it's created in:
...