Int.parse () is a forced reload function.
Int. Parse (String type variable name)
The method is to convert a string of numeric content to an int type, or to throw a ArgumentNullException exception if the string content is empty or null, or to throw a FormatException exception if the string content is not a number The OverflowException exception is thrown if the string content represents a number that is outside the range that the int type can represent.
One of the things you can do with this approach is to handle only string content, and the string content can only be within the range represented by the int type.
The formatexception exception occurs because the ABC string is not a number.
Through the online query forced reload function and usage. I found 3 functions. Convert , Parse, TryParse, (int) functions are all converting values to integers, but there are similarities and differences between the four
1 (int) variable name [coercion type conversion]:
This conversion is primarily used for numeric type conversions, from int to long,float,double,decimal types, and implicit conversions are possible, but the use of a long type to an int type requires an explicit conversion, which is how the data type is converted, or a compilation error occurs.
The method is unconditional for floating-point numbers, losing precision.
2int. TryParse (string s, out int result)
This is also the way to convert a string of numeric content to an int type, but that way is more than int. The good thing about parse is that it does not appear to be abnormal. If the conversion succeeds returns True, False is returned if the conversion fails. Obviously, the last parameter is the output value, if the conversion fails, the output value is 0, and if the conversion succeeds, the corresponding value is output.
4 Convert.ToInt32
This method not only converts a string to an int type, but also converts the value of another type to an int type. If the variable is an object or string type, when its value is null, it returns 0, without causing a program error, but if the value of this string type is string. Empty, which can still cause a program error when transitioning to int. This method rounds the floating-point number.
Int.parse ("abc") 's Fault