C#-using语句

using语句定义:

提供可确保正确使用 IDisposable 对象的方便语法。

eg:

string manyLines=@"This is line one
This is line two
Here is line three
The penultimate line is line four
This is the final, fifth line.";

using (var reader = new StringReader(manyLines))
{
    string? item;
    do {
        item = reader.ReadLine();
        Console.WriteLine(item);
    } while(item != null);
}
posted @ 2020-08-11 19:38  天山鸟  阅读(229)  评论(0编辑  收藏  举报