C #: string type

Source: Internet
Author: User

1. string is a reference type, but it differs from the reference type in common operations:

If you modify one of the strings, A New String object is created, and the other string is not changed.

Using system;

Namespace consoleapplication2

{

Classprogram

{

Staticvoid main (string [] ARGs)

{

String S1 = "a string ";

String S2 = S1;

Console. writeline ("S1 is:" + S1 );

Console. writeline ("S2 is:" + S2 );

S1 = "New String ";

Console. writeline ("S1 now is:" + S1 );

Console. writeline ("S2 now is:" + S2 );

Console. Readline ();

}

}

}

The output result is:

S1 is: a string

S2 is: a string

S1 now is: New String

S2 now is: a string

 

2. escape characters in the string:

String filepath = "C: \ User \ public ";

String filepath = @ "C: \ User \ public ";

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.