这编译为
Console.WriteLine(String.Concat("Hello World ", obj));
The String.Concat method http://msdn.microsoft.com/en-us/library/kbseaaft.aspx忽略null
参数。
它的定义如下:(来自.Net参考源)
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());
}
我不知道为什么它不简单地返回arg1.ToString()
if arg0==null
.
The String.Concat(string, string)
方法定义如下:
public static String Concat(String str0, String str1) {
if (IsNullOrEmpty(str0)) {
if (IsNullOrEmpty(str1)) {
return String.Empty;
}
return str1;
}
if (IsNullOrEmpty(str1)) {
return str0;
}
int str0Length = str0.Length;
String result = FastAllocateString(str0Length + str1.Length);
FillStringChecked(result, 0, str0);
FillStringChecked(result, str0Length, str1);
return result;
}