
Using C#, we have the traditional control blocks.
The if-than-else is:
if(boolean expression){
...
}
else if(boolean expression){
...
}
else{
...
}
The while and the do while are similar to many other languages:
while(boolean expression){
...
}
or we have:
do{
...
} while(boolean expression);
For the loop for better to look an simple sample:
for(int = 0; i<10; i++){
...
}
Something inside the block is indexed using the i that begins having the value zero and is incremented at each loop until to have the value 10 (excluded).
For the switch
switch(i){
case 0:
DoSomething0();
break;
case 1:
DoSomething1();
break;
default:
ForOtherCases();
break;
}
C# has a foreach block that we will see, in details, when talking about databases. Soon.
For exception handling we have:
try{
...
}
catch(SomeExeption e1){
...
}
finally{
...
}
The basic operators are:
Arithmetics: +
-
* (for multiplication)
/ (for division)
% (for remainder)
Logics: && (for AND)
|| (for OR)
! (for NOT)
Concatenation: +
Increment: ++ (unary)
Decrement -- (unary)
Relational: == (for EQUAL)
!=
<
>
<=
>=
Assignement: =
Scapes: \'
\"
\\
\n (for "new line")
Comentaries: //
/* */
<!-- --> (inside .XAML files)
We can talk here also about arrays (sometimes the Class ArrayList can be a better option - we will talk about this soon). For array creation we can have, by example:
int myArray = new int[4];
To include values:
myArray[0] = 9;
myArray[1] = 3;
myArray[2] = 7;
myArray[3] = 2;
or we can use:
int myArray = {9,3,7,2};
We can use a loop for to read the values:
...
for(int i=0;i<myArray.Length;i++){
...
}
...
We will see samples of the use of all these "basics" at the lessons of this tutorials serie.
PREVIOUS LESSON NEXT LESSON T.CONTENTS HOMEPAGE
