We have an app that exports very long CSV files, thousands to millions of lines. We use a StringBuilder and lots of .Appends to construct the file, and this runs out of memory around 500,000 lines. StringWriter is based on StringBuilder, and fails at the same point in my tests.
MemoryStream (or Tributary) should not have any problems dealing with a file this large, but its API is based on byte[]. I know I can convert, but this makes the code somewhat (lots?) more difficult to read.
Is there a simpler solution for writing multiple strings to a stream that I'm missing, or perhaps a clean way to implement such functionality (an extension perhaps?)