新版本的变更 / C# 8.0

using System;
using System.IO;
using System.Text;

var path = @"C:\tmp\file.txt";

//before:
using (var reader1 = new StreamReader(path, Encoding.UTF8))
{
    var text1 = reader1.ReadToEnd();
    Console.WriteLine(text1);
}

//in version 8:
using var reader2 = new StreamReader(path, Encoding.UTF8);
var text2 = reader2.ReadToEnd();
Console.WriteLine(text2);


using declaration is a variable declaration preceded by the using keyword. It tells the compiler that the variable being declared should be disposed at the end of the enclosing scope.