Int. parse (), Int. tryparse (), convert. toint32 (), (INT)

Source: Internet
Author: User
 

int I =-1;
Int. tryparse (null, out I);

after execution, I equals 0 instead of-1. Remember.

1 (INT) is a type conversion. When we convert the NT type to the long, float, double, decimal type, we can use implicit conversion, however, Explicit conversions are required from the long type to the int type. Otherwise, a compilation error occurs.

2 Int. parse () is a type-tolerant 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. If the value of the string content exceeds the range that the int type can represent, an overflowexception exception is thrown;

Int. tryparse and Int. parse is similar, but it does not produce exceptions. If the conversion is successful, true is returned, and if the conversion fails, false is returned. The last parameter is the output value. If the conversion fails, the output value is 0

4 convert. toint32 () is a type-tolerant conversion, but it is not limited to converting a string to the int type, it can also be another type of parameter; comparison: convert. if toint32 is null, 0; int is returned. if the parse parameter is null, an exception is thrown. If the convert. toint32 parameter is "", an exception is thrown. If the Int. parse parameter is "", an exception is thrown. Convert. toint32 can be converted to many types; Int. parse can only be converted to numeric strings

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.