Information Technology Reference
In-Depth Information
Multiple-Variable Declarations
You can declare multiple variables in a single declaration statement. The rules for multiple-
variable declarations are as follows:
￿
To declare multiple variables in a single statement, separate the variable names with
commas. Initializers can be included with the variable names.
￿
The variables in a multiple-variable declaration must all be of the same type.
For example, the following code shows two valid declaration statements with multiple
variables. Notice that the initialized variables can be mixed with uninitialized variables as long
as they are separated by commas. The last declaration statement is invalid because it attempts
to declare different types of variables in a single statement.
// Variable declarations--some with initializers, some without
int var3 = 7, var4, var5 = 3;
double var6, var7 = 6.52;
Type Different type
int var8, float var9; // Wrong! Can't mix types (int & float)
Using the Value of a Variable
A variable name represents the value stored by the variable. You can use the value by using the
variable name.
For example, the value of var2 is retrieved from memory and placed at the position of the
variable name, like so:
Console.WriteLine("{0}", var2);
Search WWH ::




Custom Search