public virtual string ReadToEnd();
string filePath = "C:\\testfile.txt"; using (StreamReader reader = new StreamReader(filePath)) { string fileContent = reader.ReadToEnd(); Console.WriteLine(fileContent); }
using (StreamReader reader = new StreamReader(@"C:\testfile.txt", Encoding.UTF8)) { string fileContent = reader.ReadToEnd(); Console.WriteLine(fileContent); }This code snippet reads the content of a UTF-8 encoded file located at "C:\testfile.txt" and displays it on the console. The System.IO namespace provides a set of types that enable input and output operations, and the StreamReader class is one of the types in this namespace that can be used to read character streams.