michael
michael

Reputation: 15282

LINQ: String.Join a list but add a character to that string beforehand

I have the following list:

I want to turn these strings into one string, comma separated, but I want to add a character to them first (the @ symbol). The end result should be: @alpha,@beta,@charlie,@delta

What I have right now is a non-LINQ method, but it doesn't seem "clean":

String.Concat("@", String.Join(",@", mylist));

Upvotes: 10

Views: 7249

Answers (1)

n8wrl
n8wrl

Reputation: 19765

string.Join(",", mylist.Select(s => "@" + s));

Upvotes: 22

Related Questions