. NET, have you forgotten? (vi)--further discussion of string

Source: Internet
Author: User

I. The beginning of the article

Before the article, say the purpose of writing this article. In the comments, Yang challenged my string-related ideas and wrote them, but I can't find the link now.

So, I want to talk about this old topic here.

What exactly do we understand about the commonly used type of string?

Two. Looking from C

C language is the first program language I touch. Remember when my C language teacher was a professional Java SOA teacher.

So, when she teaches C, she often gives us a time to compare with Java, although we did not know what Java is, only know that the word often appears in mobile games.

At that time, I remember the teacher's classic words: We should remember, C, there is no string this concept (in fact, we do not know what is a string), the so-called string in C represented as a character array.

So let's review the representation of the "string" in C:

Char s[]= "ABC";

Next, we can use S to invoke various "string" functions.

So we can see clearly in C, "string" is actually stored in the first address of the character array, then in the. What about the net?

Three. String vs. String

In school, this question has been asked countless times by students, especially a lot of learning Java friends.

A string is actually a string alias, and when the two are compiled to IL code, the two are no different, just as int is to System.Int32.

The difference is only:

1. String is the primitive type of the C # language and looks more like C #.

2.system.string is the primitive type of the FCL.

I often use this to:

1. If it involves language interoperability, then no doubt, it must be System.String, no longer repeat, if there is a problem, please refer to <<.net, you forget it? (i)-compliance with CLS>>.

2. If you just declare a string, I'll use string to look more readable, similar to the way you would use int i=3, and rarely see System.Int32 i=3.

3. If it is a static method that involves using a string, then I often use System.String because the string looks more like a class.

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.