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 SrivastavaRank #581 · 4.2K reputationPosted Sep 30, 2013, 6:44 PM EDT
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.
diamond diamond131 reputationPosted Sep 30, 2013, 10:48 PM EDT
Hemant SrivastavaRank #581 · 4.2K reputationPosted Oct 1, 2013, 6:26 AM EDT