I'm Writing to 2 files at a time from a row in a csv, basically I have a list of rows that some have errors so I want to create a log file with detailed errors per row and a new csv with all these rows that had errors, so I'm opening 2 streamwriters at a time, so instead of doing a using block within a using block im doing
using (var writer = new StreamWriter[] { new StreamWriter(infoFolderPath + "/Import Errors.txt"), new StreamWriter(infoFolderPath + "/Failed Import Rows.csv") })
{
foreach (var err in rowsWithErrors)
{
writer[0].WriteLine(Write row error here...);
writer[1].WriteLine(Write row in csv here...);
}
}
But the problem with this is I get an error
'StreamWriter[]': type used in a using statement must be implicitly convertible to 'System.IDisposable'.
I understand that I need to be able to dispose of the Stream after its done and the using block cant find the Dispose method because its an array of type stream and not of type stream.
So my question is, is there a way to make this work or a smarter way to write to a few files?
(please don't answer to make 2 using statements because I'm writing to more then 2 files I just simplified for the question to be easy to understand...)