我看到了这个链接:
https://learn.microsoft.com/en-us/dotnet/api/system.idisposable?view=net-6.0
代码部分是:
if (!File.Exists(filename))
throw new FileNotFoundException("The file does not exist.");
this.filename = filename;
string txt = String.Empty;
StreamReader sr = null;
try
{
sr = new StreamReader(filename);
txt = sr.ReadToEnd();
}
finally
{
if (sr != null) sr.Dispose();
}
Run Code Online (Sandbox Code Playgroud)
StreamReader什么时候变成null?