(1) Null
The NULL keyword is a literal value that represents a null reference that does not reference any object . NULL is the default value for a reference type variable. Then only the variable of the reference type can be null, if int i=null, then it is not possible, because int is a value type.
(2) "" and String.Empty
Both of these represent empty strings. But "theoretically re-opens up the memory space , and String.Empty points to a place." But the optimizer will optimize!
string. Empty does not allocate storage space, "" allocates a blank length of storage space , so it is generally used as string. Empty, in order to cross the platform later, or with String.Empty.
In C #, in most cases "" and string. Empty can be used interchangeably. Like what:
string s = "";
String s2 = string. Empty;
if (s = = string. Empty) {//} if statement established
(3) Several ways to determine the empty string, according to performance from high to low order is:
S.length = = 0 is better than s = = string. Empty better than S = = ""
Attention:
1.string str1= "" and the difference between string str2=null.
STR1 is an empty string, and an empty string is a special string, except that the value of the string is empty, and there is an accurate point in memory.
String str2=null, when defined, simply defines a reference to a string class, and str2 does not point to any place, and will error if not instantiated before use.
Original path: http://www.cnblogs.com/liuyaozhi/p/5809521.html
NULL, "", String.Empty differences in C #