I have a code, same as below:
I define it in globally :
TextWriter file = new StreamWriter("C:\\Hello.txt", true);
this give an error
for (i=0;i<100;i++)
{
double FPRate = (double)FP1.Count() / (FP1.Count() + TN1.Count()) * 100;
double DetectionRate = (double)TP1.Count() / (TP1.Count() + FN1.Count()) * 100;
file.Write(FPRate);
file.Close();
Hemant SrivastavaPosted Oct 1, 2013, 10:26 AM
diamond diamondPosted Oct 1, 2013, 2:48 AM
Hemant SrivastavaPosted Sep 30, 2013, 10:44 PM
If this is the case, you need to take out file.Close() outside of the loop.
I'd prefer code like:
using(TextWriter file = new StreamWriter("C:\\Hello.txt", true))
{
for (i=0;i<100;i++)
{
}
Here 'using' clause will take care of closing file stream itself.