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.