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? | Sololearn: Learn to code for FREE!

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?

c#

8/2/2016 4:15:39 AM

Dakota Lewis

3 Answers

New Answer

+1

convert.ToInt32 will convert null value to zero while int.Parse will get an exception.

0

thanks, i think i understand now, not sure when I would need to use parse tho lol

0

Although int.TryParse(Console.ReadLine(), out a); would prevent the program from (sometimes) crashing when the user inputs a non-integer value.