Closing StreamReader after ReadToEnd

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.


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.

If you don't specify the encoding, it will use UTF-8 automatically.

Need Your Help

How can I open WhatsApp's conversation activity using contact data?

android android-intent whatsapp

I want open what's app conversation activity cmp=com.whatsapp/.Conversation from my app.

Show only part of coreData array

ios uitableview core-data if-statement

I've a tableView which should only display objects of a coreData-entity if one of this entity-attribute is equal to a string.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.