-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Description
According to string.Join(char, params string[]) method description:
Returns:
A string that consists of the elements of value delimited by the separator character. -or-string.Emptyif value has zero elements or all the elements of value are null.
It should return string.Empty when all values are null. Well it does not, it returns string containing only the separator(s).
var values = new string[] { null, null, null };
var result1 = string.Join(';', values); // result1 = ";;"
var result2 = string.Join(';', null, null, null); // result2 = ";;"
var result3 = string.Join(";", values); // result3 = ";;"
var result4 = string.Join(";", null, null, null); // result4 = ";;"It works the same for string.Join(string, params string[]) although its description does not mention case when all the elements of value are null:
Returns:
A string that consists of the elements in value delimited by the separator string. If value if an empty array, the method returnsstring.Empty.
Descriptions on MSDN are also inconsistent, where only Join(String, Object[]) and Join(String, String[]) do not have all the elements of values are null mentioned.
I do not know how this should be handled, probably adjusting descriptions to match current behaviour is the most reasonable way to handle this but maybe it worked at some point and behaviour should be fixed.
Configuration
First found on .NET Core 3.1.
Windows 10 Professional x64
Regression?
string.Join(char, params string[])
Tested with .NET Core 2.0, 3.0, 3.1
string.Join(string, params string[])
Tested with .NET Core 2.0, 3.0, 3.1 and .NET Framework 4.6, 4.7.2.