How to transform an enumeration of long to a single string with LINQ
-
22-08-2019 - |
Question
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
Solution
If you want the long (integers?) to be comma separated try:
string str = string.Join(", ", myLongs.Select(l => l.ToString()).ToArray());
OTHER TIPS
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.
String.Join(yourIEnumerable, yourDelimiter)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow