An example. Here is the ReadToEnd method. We can call it inside a using-statement for best effect. Please change the file path before you run this program on your system.
static void Main()
using (StreamReader reader = new StreamReader(@"C:\programs\file.txt"))
// Read entire text file with ReadToEnd.
string contents = reader.ReadToEnd();
A review. Which methods are best? If you already have a StreamReader, then using ReadToEnd is probably the best solution to read an entire text file into a string.
However In other programs, where no StreamReader object exists, File.ReadAllText is probably a clearer method to use.
ReadToEndAsync. With ReadToEndAsync on StreamReader, we can achieve a significant performance boost. But this only helps when a lot of CPU usage is present during processing.