0

After watching a video I learned that int x = Convert.ToInt32(Console.ReadLine()); and int x = 0 x = int.Parse(Console.ReadLine()); essentially seem to be the same thing...why is that, and when would one way come in handy over the other?

2nd Aug 2016, 4:15 AM
Dakota Lewis
Dakota Lewis - avatar
3 Réponses
+ 1
convert.ToInt32 will convert null value to zero while int.Parse will get an exception.
2nd Aug 2016, 8:54 AM
Aravind R S
Aravind R S - avatar
0
thanks, i think i understand now, not sure when I would need to use parse tho lol
2nd Aug 2016, 1:46 PM
Dakota Lewis
Dakota Lewis - avatar
0
Although int.TryParse(Console.ReadLine(), out a); would prevent the program from (sometimes) crashing when the user inputs a non-integer value.
6th Aug 2016, 1:10 PM
Samuel Neo
Samuel Neo - avatar