public OpenRead ( System address ) : System.IO.Stream | ||
address | System | |
return | System.IO.Stream |
using System; using System.Net; class Program { static void Main(string[] args) { var client = new WebClient(); var stream = client.OpenRead("https://www.example.com"); // Do something with the stream data } }
using System; using System.IO; using System.Net; class Program { static void Main(string[] args) { var client = new WebClient(); using (var stream = client.OpenRead("https://www.example.com")) using (var reader = new StreamReader(stream)) { var content = reader.ReadToEnd(); Console.WriteLine(content); } } }This example creates a new instance of the WebClient class and calls the OpenRead method to open a readable stream from the URL "https://www.example.com". It then uses a StreamReader to read the entire contents of the stream and writes it to the console. The System.Net namespace is where the WebClient class is defined.