views:

82

answers:

3

Hello all,

I am wondering if there is an easy and clean way (one line) to transform an enumeration of long (IEnumerable) to a single string (string) with LINQ?

Thanks

A: 
String.Join(yourIEnumerable, yourDelimiter)
Boo
string.Join takes an array, not an IEnumerable, and the delimiter comes first.
Daniel Earwicker
And it takes an array of strings, not longs.
Jon Skeet
+5  A: 

If you want the long (integers?) to be comma separated try:

string str = string.Join(", ", myLongs.Select(l => l.ToString()).ToArray());
Daniel Earwicker
Cool! It works! Thanks!
Martin
+2  A: 

Sounds like a job for aggregate/fold:

var longs = new long[] {3, 2, 1, 0};
var str = longs.Aggregate("", (s, l) => s + l);
// str = "3210"

Although I am not quite sure what the question is.

Jabe