C
C#2y ago
SWEETPONY

✅ how to avoid string.Join with empty strings?

I have List<IdentifierDto> Identifiers and I'm trying to get Title from Identifiers my code:
Identifier: subject.Identifiers?
.Select( identifier => identifier?.Title )
.JoinToString( "," )
Identifier: subject.Identifiers?
.Select( identifier => identifier?.Title )
.JoinToString( "," )
some times I get result: "," and I don't understand how can I fix this
7 Replies
SWEETPONY
SWEETPONYOP2y ago
JoinToString is just string.Join
MODiX
MODiX2y ago
Ero#1111
REPL Result: Success
string[] s = { };

string.Join(",", s)
string[] s = { };

string.Join(",", s)
Result: string




Compile: 534.603ms | Execution: 36.130ms | React with ❌ to remove this embed.
MODiX
MODiX2y ago
Ero#1111
REPL Result: Success
string[] s = { "foo" };

string.Join(",", s)
string[] s = { "foo" };

string.Join(",", s)
Result: string
foo
foo
Compile: 542.459ms | Execution: 44.791ms | React with ❌ to remove this embed.
ero
ero2y ago
Has to be 2 empty or null strings then Perhaps because identifier is null
SWEETPONY
SWEETPONYOP2y ago
title is "" as I see using debugger
ero
ero2y ago
Just put a .Where(t => !string.IsNullOrEmpty(t)) in between there
SWEETPONY
SWEETPONYOP2y ago
ah.. I hadn't thought of that at all.. thanks
Want results from more Discord servers?
Add your server