May 2010
Intermediate to advanced
1752 pages
41h 17m
English
Up until this point in the chapter, when we have been defining local variables, we've explicitly specified the underlying data type of said variable.
static void DeclareExplicitVars()
{
// Explicitly typed local variables
// are declared as follows:
// dataType variableName = initialValue;
int myInt = 0;
bool myBool = true;
string myString = "Time, marches on...";
}
While it is always good practice to explicitly specify the data type of each variable, the C# language does provide for implicitly typing of local variables using the var keyword. The var keyword can be used in place of specifying a specific data type (such as int, bool, or string). When you do so, the compiler will automatically ...