C # Learning Note One (data type, escape character)

Source: Internet
Author: User

    1. Data type conversions:
      1. 1 using Convert
      2. 1 For example: string str = "1245.351";
        Double db = convert.todouble(str);
      3. 1 Use cast type, that is, precede the type with parentheses (type name)
      4. 1 For example: double n1 = (double) N1
      5. 1 Note: Each type can be converted to a string type.
      6. 1 For example: string str = n1. ToString ();
        String str2 = db. ToString ();
      7. 1 Using the Parse method
      8. 1 For example: int n3 = Int.Parse(str);

2. Escape characters:

2.1 When using @, you can save the meaning of the escape character, the original format output!

    2.2 Example: String bb = @ "Moon Light Before Bed"
Suspected to be ground frost "; (output here with a carriage return)

string path = @ "f:\c#\ self-taught. avi"; (The output path can be directly output without using a double slash)

 3. Placeholder {0}{1} ...

3.1 Placeholder {0:0.00} means:

Double DB2 = 3.333333;

Console.WriteLine ("{0:0.00}", DB2); The placeholder output here is two decimal places

3.2 The position of the placeholder is the title:

The following N1, N2, DB, DB2 correspond to {0},{1},{2},{3}. So the adjustment {0},{1},{2},{3} here in the double quotation mark position can be used for different positions to output
Console.WriteLine ("\n{3};\n{1};\n{0};\n{2}", N1, N2, DB, DB2);

C # Learning Note One (data type, escape character)

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.