1, int is suitable for conversion between simple data types, the default integral type of C # is int32 (bool type is not supported);
2, Int. Parse (String sparameter) is a constructor, and parameter types only support string types;
3. Convert.ToInt32 () is suitable for converting object type to int type;
4, Convert.ToInt32 () and Int. The nuances of Parse ():
For null (NULL) processing, CONVERT.TOINT32 (NULL) returns 0 without generating any exceptions, but int. Parse (NULL) produces an exception.
For example:
If we take the value of a parameter page from the URL, we know that the value is an int, so we can use Convert.ToInt32 (request.querystring["page") or int. Parse (request.querystring["page"]), but 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 in the original there is no such parameter and continue the next processing, This can have unintended effects, and in the latter case 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 for missing parameters, rather than the parameter value as a limit processing.
5. Another difference is:
(1). Convert.ToInt32 (double value) if value is a number in the middle of two integers, returns the even of the two, that is, 4.5 is converted to 4, and 5.5 is converted to 6;
(2). Int (4.6) = 4,int conversion Other numeric types are int without rounding, casting (intercepting integer part);
(3). Int. Parse (4.5) will directly error: "The input string is malformed."
Int. Parse is to convert a 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.
Summarize:
(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 # integers three coercion types convert int, convert.toint32 (), Int. The difference between the Parse ()