Skip to content

Instantly share code, notes, and snippets.

@dieseltravis
Created July 16, 2019 22:10
Show Gist options
  • Select an option

  • Save dieseltravis/9040971eb126325d505ff01ecbe1efb4 to your computer and use it in GitHub Desktop.

Select an option

Save dieseltravis/9040971eb126325d505ff01ecbe1efb4 to your computer and use it in GitHub Desktop.
lazily using LINQ Aggregate to reduce a List of strings to a CSV format (this is only for quick/dirty applications, it doesn't escape values)
//using System.Linq;
List<List<string>> SomeData = new List<List<string>>();
// add values (first item as column names)
SomeData.Add(new List<string>
{
"Id",
"Name",
"etc"
});
string csv = SomeData.Aggregate("", (acc, list) => acc + string.Join(",", list) + "\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment