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:

skendrot said...

I much prefer string.join to accomplish this.

string.Join(" ", words);