+ 1

Why it is necessary to put "+"after x and before y to display correct output. Via writeLine method ?

int x = 3; int y = x--; Console.WriteLine(x+" "+y);

10th Dec 2016, 4:39 AM
Zeen
2 ответов
+ 2
Because you're adding the values together to create the output string. An alternative would be Console.WriteLine("{0} {1}", x, y);. In this case you use the formatting of strings to generate the output. (Also found under string.Format(...);)
10th Dec 2016, 6:44 AM
Leon Lichtblau
Leon Lichtblau - avatar
0
In the above expression +" " concatinate the space between x and y.
30th Dec 2016, 3:46 AM
Demo Hi
Demo Hi - avatar