Someone asked me, are there any things that might be confusing in c# if i was a C++ programmer?
I say yes, but i like to call it simplicity.
Simplicity in C# comes to break apart all the annoying things in C/C++. for example, have you ever wrote an if statement in C/C++ that looks like this:
if (x = 0) { . . . }
and wondered for days what went wrong? (if you have'nt noticed, this simple if statement actually assign x with 0, and not comparing it with 0).
In C# you cant do that, C# compiler will complain that this (x=0) statement is not a bool one, and cannot be converted to bool, which means that you must explicitly state every if/while/... as bool, that cannot be converted to other types.
Another thing is Switch statements...a very common place for fall downs;
In C/C++ something like this is ok:
switch(x) {
case 1:
case 2:
[...something...]
break;
case 3:
case 4:
[...something...]
break;
}
What it means is that case 1 and 2 are "fall through". when x is 1, the switch statement will fall through 2 and up until it hit the break.
in C# every case has a break, this line on code (6 lines if you will) will cause the compiler of c# to generate a break after EVERY case. and if we wanted fall through? well consider this:
switch(x) {
case 1:
goto case 2;
case 2:
[...something...]
break;
case 3:
goto case 4;
case 4:
[...something...]
break;
}
to gain the same effect.
(c)sagiv
I will be happy to get comments this line of articles.
10:30:32 AM
|