The biggest difference between the two methods is their handling of the null value: Convert.ToInt32 (NULL) returns 0 without any exception, but int. Parse (NULL) produces an exception.
Do not understand Chu Convert.ToInt32 and int.parse () fine nuances, do not mess with, otherwise it may produce unpredictable results. For example, if you take a parameter page value from a URL, we know that the value is an int, so you can use the
Convert.ToInt32 (request.querystring["page"])
Or
Int. Parse (request.querystring["page"])
However, if the page parameter does not exist in the URL, then the former will return 0,0 may be a valid value, so you do not know that the URL is not at all there is no such parameter and continue the next processing, which may produce unexpected effects, In the latter way, there is no page this argument throws an exception, we can catch the exception and then do the corresponding processing, such as prompting the user to lack of parameters, rather than the parameter value as a limit processing.
Int. Parse is converting string to int
Convert.ToInt32 is the conversion of objects that inherit from object to int.
You get an object, you want to convert it to int, with Int. It is not possible to parse, but to use Convert.ToInt32.
Personal Summary:
(1) Convert.ToInt32 parameters are more, Int.parse can only convert string types.
(2) The parse is to convert a string into a int,char,double .... And so on, that is *. Parse (string) must be a string in parentheses.
(3) Convert can provide multiple types of conversions, that is, convert.* () can be of many types (including string) in parentheses.
C#:convert.toint32 () and Int. The difference between Parse () [Go]