Int. Parse (), Int. The difference between TryParse () and Convert.ToInt32 ()

Source: Internet
Author: User

1:Int. Parse (one parameter)

This parameter must satisfy:

1 can only be a string;

2 can only be an "integer" string, which is the form after various integer tostring () , and cannot be a floating-point type.

2:Int. TryParse (parameter A, parameter b);

This method can be considered an int. The Parse () method upgrades, that is, an exception handler, returns False if an exception occurs, and returns the output parameter to 0;

Note that parameter A, also must be a string or null to

For example:

int b;
Int. TryParse ("54.1", out B);
Response.Write (b);

The result is: 0

int b;
Int. TryParse (Null,out b);
Response.Write (b);

The result is: 0

int b=12;
Int. TryParse ("Fdfds", out B);
Response.Write (b);

The result is: 0

int b=12;
Int. TryParse ("123456", out B);
Response.Write (b);

The result is: 123456, not 12

3:convert.toint32 (one parameter)

This parameter can be a variety of types, but this string type "DFADF", "123.1" will error

int b= convert.toint32 (null);
Response.Write (b);

Results: 0

bool A = false;
int b= Convert.ToInt32 (a);
Response.Write (b);

Results: 0

int b= Convert.ToInt32 (1253.1);
Response.Write (b);

Results: 1253

int b= Convert.ToInt32 (1253.5);
Response.Write (b);

Results: 1254

Int. Parse (), Int. The difference between TryParse () and Convert.ToInt32 ()

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.