Install-Package Linq.Csv
Add the following using statement which will allow you to use the
using Linq.Csv;
Then you can use any of the following api
string csvContent = Enumerable.Range(1, 50).Csv(new string[] { "Number" }, p => p);
string csvContent = Enumerable.Range(1, 50).Csv(p => p);
You can also write directly to the stream.
Stream file = File.OpenWrite("output");
file.WriteCsv(Enumerable.Range(1, 50), p => p, p => p * p);