Archive for the ‘E- Variables’ Category

Declaring Varibles

Sunday, March 8th, 2009

Declaring variables in C#

Here i am not talking about arrays or more complex structures, the basic variable declaration and initialization is as follows

Lines that start with // are not for the compiler, they are comments and effectivly ignored on compile

//Declare an integer
int myInteger;
//Give it initial value
myInteger = 15;
//Declare and Initialize @ once
int myOtherInteger = 16;
//Declare More than 1 variable at once
int var1, var2, var3;
//More on one line, Declare and initialize many
int var4 = 45, var5 = 46, var6 = 47;

Surely you can replace int with float or string or bool or any other.