C #, int to string, string to int

Source: Internet
Author: User
1, int to string
Use tostring
Or convert. tostring () is as follows:

For example:
Int varint = 1;
String varstring = convert. tostring (varint );
String varstring2 = varint. tostring ();

2. Convert string to int.
If it is determined that the character string can be converted to a number, Int. parse (string s) can be used. This statement returns the converted int value;
If you cannot determine whether the string can be converted to a number, you can use Int. tryparse (string S, out int result). The return value of this statement is bool, indicating whether the conversion operation is successful. The result parameter is a variable that stores the conversion result.

For example:
String STR = string. empty;
STR = "123 ";
Int result = int. parse (STR );

String STR = string. empty;
STR = "XYZ ";
Int result;
Int. tryparse (STR, out result );

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.