1、一定要把可能会出错的代码段放入try,否则程序有崩溃的危险。

2、自己懒得手动释放资源或者来不及释放资源的时候就用using() 吧,读写文件的时候会很有用。

 

using (StreamWriter sw = new StreamWriter(LOG_FILE, true, System.Text.Encoding.UTF8))
{
  sw.Write(log);
  sw.Flush();
  sw.Close();
  sw.Dispose();
}

 

相关文章:

  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2021-11-18
  • 2021-10-19
  • 2022-12-23
猜你喜欢
  • 2021-12-26
  • 2021-07-04
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
相关资源
相似解决方案