代码在运行多次后切断字符串

时间:2010-12-07 19:40:09

标签: c# string text-files streamwriter

此代码循环运行。第38次运行后,打印到文本文件的字符串在第二个“M”后立即切断,甚至不打印逗号,然后停止打印所有内容并结束。

这可能是什么原因?

private static void LogPayment(CDefeasancePayment paymentToLog, System.IO.StreamWriter outfile)
{
    string line = "AddDefeasancePayment(DateTime.Parse(\"" + paymentToLog.PaymentDate.ToShortDateString() +
                  "\"), " + paymentToLog.Interest +
                  "M, " + paymentToLog.Principal + "M, DateTime.Parse(\"" +
                  paymentToLog.StripDate.ToShortDateString() + "\"), " + paymentToLog.StripPrice +
                  "M);\n";
    outfile.Write(line);
}

1 个答案:

答案 0 :(得分:4)

确保已刷新outfile缓冲区。