NULL, "", String. Empty differences in C,
(1) NULL
The null keyword is a text value that does not reference any object's null reference. 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 are empty strings. But "" theoretically re-opens the memory space, and String. Empty points to one. But the optimizer will optimize it!
String. Empty does not allocate a bucket. "" It is used to allocate a bucket with an Empty length. Therefore, string. empty is generally used. For future cross-platform use, string. Empty is used.
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
(3) 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 = ""
Note:
1. The difference between string str1 = "" and string str2 = null.
Str1 is an empty string, and a null string is a special string, but the value of this string is null, Which is accurate to the memory,
String str2 = null. After this definition, a reference to the string class is defined. str2 does not point to any place. If it is not instantiated before use, an error is returned.