Why is there no exception when adding null to a string?
问题 Why doesnt this throw an exception dont understand, obj is null object obj = null; Console.WriteLine("Hello World " + obj); 回答1: This compiles to Console.WriteLine(String.Concat("Hello World ", obj)); The String.Concat method ignores null parameters. It's defined like this: (From the .Net reference source) public static String Concat(Object arg0, Object arg1) { if (arg0==null) { arg0 = String.Empty; } if (arg1==null) { arg1 = String.Empty; } return Concat(arg0.ToString(), arg1.ToString()); }