+ 2
Can someone explain to me how exactly this code works?
This was in C# challenge, it returns 1500, and I don't know what is going on here :c int a = 1500; int b = 2000 % 1; //int c = 1000; { if(b>a)//c+) Console.Write("2000"); } { Console.Write("1500"); } /*{ Console.Write("1000"); }*/
6 Respostas
+ 18
Let's remove the parts which have been commented out.
int a = 1500;
int b = 2000 % 1;
{
if(b>a)
Console.Write("2000");
}
{
Console.Write("1500");
}
This should now be clear why the output is 1500.
+ 15
a=1500;
b=2000%1=0;
Since, 0 is not bigger than 1500,
thus only
Console.WriteLine("1500"); runs
+ 15
If you are writing a songle line statement after if or else, then adding curly braces are optional else mandatory.
This program is doing useless things, so ignore as Hasty Rei said.
+ 14
1) If you have no braces after if statement, only the first statement following the if statement will be executed if condition is fulfilled.
2) They do nothing. :D
+ 3
Thanks, I'm learning C# from yesterday, you've helped a lot! ^^
+ 2
This part I understand, but
1. why there are no parentheses after if statement?
2. why if statement and write 1500 func are in parentheses which seems to do nothing?