Conversion between C # strings and data

Source: Internet
Author: User

In C #, there is more than a conversion between data of numeric types, and strings and numbers can be converted to each other, but only in different ways.

1 numeric conversions to char type

It is possible to convert numeric data to strings with the ToString () method.

int num1=10
String Mynum=num1. ToString ();

2 string converted to numeric type

Convert string data to numeric using the Pares () method
The string is converted to integer with int. Pares ()

String str= "13";
int Number=int. Pares (str);
The string is converted to a double-precision floating-point double. Pares () string

String str= "14";
Double number =double. Pares (str);

The string is converted to a single-precision float float. Parse (String)

String str= "15";
Float number=float. Pares (str);

Not knowing that a string can be converted to numeric data, only a string capable of being represented as a number can be converted, such as the name "Zhang San", and the conversion to a number that does not conform to an expression is not possible.

Note the arguments in Pares () brackets can only be strings and cannot be other data types.

Conversion between C # strings and data

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.