Null,string.Empty,0,“”的区别
object a = null; object b = 0; object c = string.Empty; object d = ""; object e; if (a == null) { Console.WriteLine("a is null"); } if (b == null) { Console.WriteLine("b is null"); } if (c == null) { Console.WriteLine("c is null"); } if (d == null) { Console.WriteLine("d is null"); } if (b == c) { Console.WriteLine("b is c"); } if (b == d) { Console.WriteLine("b is d"); } if (c == d) { Console.WriteLine("c is d"); }
结果为:
从结果可以看出来这之间的大致关系。
a和e的区别
a是已赋值了,但是值为null,e是未赋值。