using System; using System.IO; namespace ReadToEndExample { class Program { static void Main(string[] args) { string filePath = "example.txt"; using (StreamReader reader = new StreamReader(filePath)) { string content = reader.ReadToEnd(); Console.WriteLine(content); } } } }
using System; using System.Net; namespace WebClientExample { class Program { static void Main(string[] args) { string url = "https://www.example.com"; using (WebClient client = new WebClient()) { string content = client.DownloadString(url); Console.WriteLine(content); } } } }This code reads the contents of a web page at "https://www.example.com" using the WebClient class and writes them to the console. The System ReadToEnd method is part of the System.IO library.