String is a reference type;
String STR = NULL: no memory space is created. Str stores null reference pointers;
String STR = "" memory space is created. Str stores pointers to the heap.
Simply put:
String STR = "";
Give you a blank sheet of paper;
String STR = NULL;
No white paper.
String. Empty is equivalent ""
It is generally used for string initialization.
For example:
String;
Console. writeline (a); // an error is reported because a is not initialized.
No error is reported below:
String A = string. empty;
Console. writeline ();
Or for comparison:
If (A = "")
If (A = string. Empty)
The above two statements have the same effect.
String. Empty does not allocate storage space
"" Allocate a bucket with an empty Length
Therefore, we generally use string. Empty
For the sake of future cross-platform use string. Empty
In C #, "" And string. Empty Can be used interchangeably. For example:
String S = "";
String S2 = string. empty;
If (S = string. Empty ){
//
}
If statement is true
Several methods for determining as a Null String, in the order of performance from high to low:
S. Length = 0 is better than S = string. Empty is better than S = ""
About string. the problem with empty and null is that both of them indicate null strings, and one of them focuses on string str1 = string. the difference between empty and string str2 = NULL. After this definition, str1 is an empty string, and the empty string is a special string, except that the value of this string is null, in the memory, there is an accurate point. String str2 = NULL. After this definition, only a reference to the string class is defined, and str2 does not point to any place, if it is not instantiated before use, an error will be reported. Textbox1.text is a zero-length string "".