Posts Tagged ‘LINQ’

Converting IEnumerable to a Comma-Delimited String

I’m not sure whether it’s the fastest way to convert an enumerable collection of longs or ints to a comma-delimited list in C#, but it might be the shortest.

  1. IEnumerable<long> ids = new long[]{1,3,4,5};
  2. string delimitedIds = string.Join(",", ids.Select(x => x.ToString()).ToArray());

If you need a LINQ-free version for backward compatibility, check out Missing Functions on IEnumerable on Steve Cooper’s blog.