是否有可能以某种方式调用ReadToEnd方法在建设这样后关闭StreamReader的:
Is it possible somehow to close StreamReader after calling ReadToEnd method in construction like this:
string s = new StreamReader("filename", Encoding.UTF8).ReadToEnd();
任何替代优雅的建筑,相同的语法也将被接受。
Any alternative elegant construction with the same semantics will be also accepted.
我觉得你的方法真的就是后的 File.ReadAllText ,如果你只是想读在最短的code文件中的所有文本。
I think the method you're really after is File.ReadAllText, if you're just trying to read all the text from a file in the shortest possible code.
如果您不指定编码,将使用UTF-8会自动。
If you don't specify the encoding, it will use UTF-8 automatically.