+ 1
Why the secondNumber is 0?
8 Respostas
+ 2
On sololearn you have to input all values at the beginning.
input format:
2 [enter]
3
If you enter only one value, secondNumber will be 0. Not sure but maybe because 0 is the default value for integers.
+ 2
It's not. Unless you entered "0", in which case the answer is "because you entered it".
+ 2
If the first one is empty, we have an empty string that seems not to be cast to an integer.
For the second one we reached the end of the stream, which is null (no empty string).
I am just guessing.
+ 1
Simon Sauter I only entered 5 without a return and second number is zero. So maybe an empty input is converting to zero by the Convert.ToInt32
+ 1
Paul K Sadler Denise Roßberg I didn't notice that. Interesting. If you enter only one number the second is printed as "0", but if you enter no number the program throws an error.
+ 1
Console.ReadLine() returns null if there is nothing to be read. Looks like null will just be cast to 0:
Console.WriteLine(Convert.ToInt32(null));
+ 1
Lisa any idea why that works for the second input, but not the first?
0
Lisa that sounds like a reasonable guess