In C #, "" and string. Empty can be used interchangeably. For example:
String s = "";
String s2 = string. Empty;
If (s = string. Empty ){
}
Among them, string. Empty and string str = "" are allocated with memory space, and both of them point to the same location.
String str = Null, no memory space is allocated.
For the sake of future cross-platform use string. empty
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 = ""
Your own understanding of them
1. The null keyword is a text value that does not reference any null reference of an object. Null is the default value of the reference type variable. Then, only the referenced variable can be NULL. If int I = null, it is not possible because Int is of the value type.
2. "" and String. Empty
Both of these are empty strings, with a focus on the difference between string str1 = "" and string str2 = null. After this definition, str1 is an empty string, A null string is a special string, except that the value of this string is null and has an accurate point in memory. string str2 = null. After this definition, only a string class reference is defined. str2 does not point to any place. If it is not instantiated before use, an error is returned.