Im using StreamWriter in a loop and on the first write attempt I am getting the "Cannot write to a closed TextWriter" error but the resource has just been opened so im not sure why this is, here is the code:-
if(File.Exists(filename) == false)
{
using (sw = new StreamWriter(File.Create(filename)));
{
for(int i =0; i < mfeTempLoserList.Count -1; i++)
{
sw.WriteLine(mfeTempLoserList[i]); //Error happening here on first loop
}
}
}