Difference between int.Parse() and Convert.ToInt32

9. April 2011 10:36 by Mahmoud Farhat in C#, C#, C#, C#  //  Tags:   //   Comments (0)

 

This post just a slight tip for showing the difference between Int32.parse(string) and Convert.ToInt32(string)

 

Int32.parse(string)

- Int32.Parse(string str) method converts the string representation of a number to integer 32 bit.
- when str is a null reference it will throw ArgumentNullException.
- if str is other than integer value it will throw FormatException.
- when str represents a number less than MinValue or greater than MaxValue it will throw OverflowException.

Convert.ToInt32(string)

- Convert.ToInt32(string str) method converts the string representation of a number to integer 32 bit.
- when str is a null reference it will return 0 rather than throw ArgumentNullException.
- if str is other than integer value it will throw FormatException.
- when str represents a number less than MinValue or greater than MaxValue it will throw OverflowException.