In your favorite decompiler you can see the code for the method
public static string Join(string separator, params object[] values) { if (values == null) throw new ArgumentNullException("values"); if (values.Length == 0 || values[0] == null) return string.Empty; if (separator == null) separator = string.Empty; StringBuilder sb = StringBuilderCache.Acquire(16); string str1 = values[0].ToString(); if (str1 != null) sb.Append(str1); for (int index = 1; index < values.Length; ++index) { sb.Append(separator); if (values[index] != null) { string str2 = values[index].ToString(); if (str2 != null) sb.Append(str2); } } return StringBuilderCache.GetStringAndRelease(sb); }
The part responsible for the special behavior
if (values.Length == 0 || values[0] == null) return string.Empty;
but we can see a few lines below
string str1 = values[0].ToString(); if (str1 != null) sb.Append(str1);
It seems rather strange to me to return to values[0] == null , but to process values[0].ToString() == null . Combined with the wording in MSDN (βproblemβ, βworkaroundβ), the fact that this overload is relatively new (.NET 4.0), and the fact that other Join have a different implementation that accept null as the first element, it looks like an error to me and is not really the intended exception.
Of course, this is only my interpretation, not the final answer ...
Vache
source share