Determines whether the user input is an int integer !, Int integer

Source: Internet
Author: User

Determines whether the user input is an int integer !, Int integer

1 int age = 0; 2 string vv = this. textBox2.Text; 3 if (int. tryParse (vv, out age) 4 {5 age = int. parse (this. textBox2.Text); 6 7} 8 else 9 {10 MessageBox. show ("Age is not plastic"); 11 return; 12 13}
Int. Parse () is a type of capacity conversion. It indicates converting the numeric content string to the int type.
If the string is null, an ArgumentNullException exception is thrown;
If the string content is not a number, a FormatException is thrown;
OverflowException is thrown if the number indicated by the string content exceeds the range indicated by the int type;

Int. TryParse is similar to int. Parse, but it does not produce exceptions. If the conversion is successful, true is returned. If the conversion fails, false is returned. The last parameter is the output value. If the conversion fails, the output value is 0.

------- From lingbo hut --- Feng Chao's notes

Related Article

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.