Thursday, August 16, 2012

Using Linq to concatenate strings

string[]words = new string[]{"hello","world"};
string concatenated = words.Aggregate((w,n) => w + " " + n);

Returns "hello world"

1 comment:

  1. I much prefer string.join to accomplish this.

    string.Join(" ", words);

    ReplyDelete

Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.