Possible Duplicate:
Whats the main difference between int.Parse() and Convert.ToInt32
Hi
I want to know what is the different between :
Convert.ToInt16 or Convert.ToInt32 or Convert.ToInt64
vs
Int.Parse
both of them are doing the same thing so just want to know what the different?
Convert.ToInt
converts an object to an integer and returns 0 if the value was null.
int x = Convert.ToInt32("43"); // x = 43;
int x = Convert.ToInt32(null); // x = 0;
int x = Convert.ToInt32("abc"); // throws FormatException
Parse
convert a string to an integer and throws an exception if the value wasn't able to convert
int x = int.Parse("43"); // x = 43;
int x = int.Parse(null); // x throws an ArgumentNullException
int x = int.Parse("abc"); // throws an FormatException
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With