using System.IO; string contents = File.ReadAllText("example.txt"); Console.WriteLine(contents);
using System.Threading; void MyThreadFunction() { Console.WriteLine("Hello from a new thread!"); } Thread t = new Thread(new ThreadStart(MyThreadFunction)); t.Start();
using System.Net; WebRequest request = WebRequest.Create("https://example.com/"); WebResponse response = request.GetResponse(); using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { string contents = reader.ReadToEnd(); Console.WriteLine(contents); }Here, we use the `WebRequest` and `WebResponse` classes from the `System.Net` namespace to send an HTTP GET request to a URL ("https://example.com/") and retrieve the response. We then read the response body into a string and print it to the console.