Used to always use Int. Parse (x) or Convert.toint64 (x), later found in the project that if the value of the x variable is null, it will be an error, even if I write int. Parse (x=x?? ") 0 ") means:" If x is empty, give X a value of ' 0 ' string, and then convert to int ", or not escape the danger of error, and then the next int accidentally point out TryParse (), it appeared as an angel saved me, format: Int. TryParse (X,out y)//x is the string to be converted, and y is a variable of type int;
Usually I write like this:
int y=0; int Num; if (int .) TryParse ("9", out y)) { Num=y; If "9" cannot be converted to int type, the expression in if is false, and if the conversion succeeds assign to the variable y; Then we can use Y to help us to get the value for unlimited times, (*^__^*) hehe ... Int. The biggest benefit of TryParse is that no longer have to worry about the type conversion times wrong;}// except Int. TryParse (), I believe you have thought of, the same, there are decimal. TryParse () and so on;
Why now use int instead. TryParse.