The difference between string and string in C #

Source: Internet
Author: User

From the location, say:

    • 1, uppercase string is a string in the. NET framework, and a lowercase string is a string in the C # language
    • 2. If you delete the using System, you cannot use uppercase String,system is a function name in the. NET Framework class Library

From the nature:

    • 1. String is a keyword, string is a class, string cannot be the name of a class, struct, enumeration, field, variable, method, property
    • 2, write code in C # as far as possible to use lowercase string, compared with the specification. If you can use uppercase strings in the pursuit of efficiency, because the lowercase string becomes the uppercase string after compilation, it can reduce the load for compilation and thus improve the efficiency of the operation.
    • 3. String that represents Unicode character strings, string is an alias for string in the. NET framework, and is more intuitive to test for string equality

String Details:

string string  //  output value is 0

string S1 = string. A string variable that points to an empty string, S1 does not occupy storage space, and the S1 variable can be used

string string  //  output value is 0

String s2 = ""; an empty string pointing to "S2", which takes up a byte storage space because the escape character, \ n, is the end of the string, and the S2 variable can be used

string NULL  //  throws an exception of type ' System.NullReferenceException ' (that is, a null reference)

string s3 = ""; A variable that does not point to any storage space, S3 variable cannot be used

Single Character Segmentation:

string " ABCDEABCDEABCDE " ; string [] Sarray = S.split ('C'); foreach (string in sarray) {    Console.WriteLine (i.tostring ());} // output The following result: Abdeabdeabde

Multiple character splits:

strings ="ABCDEABCDEABCDE";string[] SArray1 = S.split (New Char[3]{'C','D','e'});foreach(stringIinchsArray1) {Console.WriteLine (i.ToString ());}//output The following result:Ababab

Multiple-character segmentation (regular expressions):

string " Agcsmallmacsmallgggsmallytx " ; string " Small " , regexoptions.ignorecase); foreach (string in resultstring) {    Console.WriteLine (i.tostring ());} // output The following result: Agcmacgggytx  

The difference between string and string in C #

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.