dotnet / dotnet/dotnet-api-docs
string.Join with only null values returns delimiters instead of string.Empty
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 950
- Fork
- 1.7k
- Merge medio
- 2g 19h
- PR unite (30g)
- 52
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Iniziare dalla documentazione dell'API string.Join e confrontare le descrizioni del valore restituito per gli overload con separatore char e string, incluse le varianti String[] e Object[]. Confermare il comportamento documentato rispetto agli esempi nell'issue; il lavoro è completato quando le descrizioni degli overload interessati corrispondono in modo coerente al comportamento stabilito o identificano chiaramente una modifica necessaria al runtime.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100