【发布时间】:2020-07-10 11:30:55
【问题描述】:
您好,我在浏览 C# 中的一些示例时遇到了一些类似于以下的代码:
private void WriteData(string filePath)
{
using var writer = new System.IO.StreamWriter(filePath);
//Logic to write data here
}
想知道using在变量声明中的用途和意义。
还有它与简单的变量声明有什么不同:
var writer = new System.IO.StreamWriter(filePath);
【问题讨论】:
-
@LasseV.Karlsen 它被接受的答案也显示了新风格
-
啊,是的。谢谢,没注意。