[ACCEPTED]-what is the difference between Convert.ToInt16 or 32 or 64 and Int.Parse?-c#
Convert.ToInt
converts an object to an integer and returns 3 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 2 integer and throws an exception if the value 1 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
Convert.ToInt32
will return 0 if the input string is null. Int32.Parse
will 1 throw an exception.
Convert.To(s)
doesn't throw an exception when argument 5 is null, butParse()
does.Convert.To(s)
returns 0 when argument 4 is null.Int.Parse()
andInt.TryParse()
can only convert strings.Convert.To(s)
can 3 take any class that implements IConvertible.Hence,Convert.To(s)
is 2 probably a wee bit slower thanInt.Parse()
because it has to ask 1 its argument what it's type is.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.