ReadToEnd后关闭的StreamReader [英] Closing StreamReader after ReadToEnd

查看:465
本文介绍了ReadToEnd后关闭的StreamReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能以某种方式调用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.

这篇关于ReadToEnd后关闭的StreamReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆