开发者

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

开发者 https://www.devze.com 2023-03-11 06:33 出处:网络
I have the following list: alpha beta charlie delta I want to turn these strings into one string, co开发者_如何学Cmma separated, but I want to add a character to them first (the @ symbol). The end

I have the following list:

  • alpha
  • beta
  • charlie
  • delta

I want to turn these strings into one string, co开发者_如何学Cmma 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));


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

精彩评论

暂无评论...
验证码 换一张
取 消