int i =-1;
BOOL B = Int. TryParse (null, out i);
When execution is complete, b equals false,i equals 0, not equal to-1, remember.
int i =-1;
BOOL B = Int. TryParse ("123", out I);
After execution, b equals true,i equals 123;
1, (int) is a type conversion; when we 觟 the NT type to the Long,float,double,decimal type, we can use implicit conversions, but when we need to use an explicit conversion from the long type to the int type, a compilation error is generated.
2, Int. Parse () is a class-tolerant transformation that converts a string of numeric content into an int type.
Throws a ArgumentNullException exception if the string is empty;
Throws a FormatException exception if the string content is not a number;
Throws a OverflowException exception if the string content represents a number that is outside the range represented by the int type;
3, Int. TryParse and Int. Parse is more similar, but it does not produce an exception, the conversion succeeds and returns True, and the conversion fails to return false.
The last parameter is the output value, if the conversion fails, the output value is 0, if the conversion succeeds, the output value is the converted int value
4, Convert.ToInt32 () is a class-tolerant conversion, but it is not limited to converting a string to an int type, or another type of parameter;
Comparison: When the Convert.ToInt32 parameter is null, returns 0; Int. Throws an exception when the Parse parameter is null. Throws an exception when the Convert.ToInt32 parameter is ""; Int. Throws an exception when the Parse parameter is "". Convert.ToInt32 can convert more types; int. Parse can only convert a string of numeric types. Int. TryParse compared to the above two methods are more secure, will not error, in some cases, useful a lot!
C # Int. Parse () and Int. TryParse ()