C#,int turn into string,string and turn into int

Source: Internet
Author: User

Reprint: http://www.cnblogs.com/xshy3412/archive/2007/08/29/874362.html

1,int turns into a string
With ToString
or convert.tostring () as follows

For example:
int varint = 1;
String varstring = Convert.ToString (varint);
String varString2 = Varint.tostring ();

2,string Turn int
If you determine that a character in a string can be converted to a number, you can use Int. Parse (string s), which returns the converted int value;
If you cannot determine whether a string can be converted to a number, you can use Int. TryParse (string s, out int result), which returns a bool value indicating whether the conversion operation was successful, and the parameter result is a variable that holds the result of the conversion.

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);

C#,int turn into string,string and turn into int

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.