Declaring and Referencing Variables

Variables are similar to constants in that when you reference a variable's name in code, Visual C# .NET substitutes the variable's value in place of the variable name when the code executes. This doesn't happen at compile time, though. Instead, it happens at runtime—the moment the variable is referenced. This is because variables, unlike constants, can have their values changed at any time.

Declaring Variables

The act of defining a variable is called declaring. (Variables with scope other than local are dimensioned in a slightly different way, as discussed in the section on scope.) You've already defined variables in previous hours, so a declaration statement should look familiar to you:

							datatype
							variablename ...

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.