Why now use int instead. TryParse.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.