1. String StringsWhy is string a reference type?
Because string is a direct derivation of System.Object, it is a reference type.
why doesn't the string use new?
In fact, it can be new, generally we do not do so. First look at string a= "123"; String b= "123"; string s =new string (' 1 '); string t =new string (' 1 ');
Here A and b actually refer to the address of the same string, and the new one here is to reassign the address, so s and T are different reference addresses;
The CLR says that C # does not allow the use of the new operator to construct string objects from literal values;
If you use unsafe code, you can construct a string from char* or sbyte*, and then use new. string s =new string (' 1 '); string t =new string (' 1 ');
What is the difference between string and StringBuilder?
String strings are immutable, so it returns a new string when the string is manipulated. If a large number of string operations, a large number of string objects are created on the heap, resulting in more frequent garbage collection, which can affect performance;
The StringBuilder represents a mutable string.
C # Basics (interview often asked)