What’s in This Chapter
Wrox.com Downloads for This Chapter
Please note that all the code examples for this chapter are available as a part of this chapter’s code download on the book’s website at www.wrox.com/go/csharp5programmersref on the Download Code tab.
A variable is a program element that stores a value. Some of the values that a variable might contain include a number, string, character, date, or object representing something complex such as a customer or business report.
A program uses variables to hold and manipulate values. For example, if some variables hold numbers, the program can apply arithmetic operations to them. If the variables hold strings, the program can use string operations on them such as concatenating them, searching them for particular substrings, and extracting substrings from them.
Four factors determine a variable’s exact behavior:
forloop, only other code inside the loop can use the variable. If you declare a variable at the top of a method, only the code in the method can use the variable.