public ReadBlock ( char buffer, int index, int count ) : int | ||
buffer | char | |
index | int | |
count | int | |
return | int |
using System.IO; string path = @"C:\example\file.txt"; // Create an instance of StreamReader using (StreamReader reader = new StreamReader(path)) { // Read 10 characters from the file at a time char[] buffer = new char[10]; int offset = 0; int count = 10; int charsRead = reader.ReadBlock(buffer, offset, count); // Display the characters read from the file string text = new string(buffer, offset, charsRead); Console.WriteLine(text); }
using System.IO; using System.Net.Sockets; TcpClient client = new TcpClient("server", 80); // Get the network stream associated with the client NetworkStream stream = client.GetStream(); // Create an instance of StreamReader using (StreamReader reader = new StreamReader(stream)) { // Read 1024 characters from the stream at a time char[] buffer = new char[1024]; int offset = 0; int count = 1024; int charsRead = reader.ReadBlock(buffer, offset, count); // Display the characters read from the network stream string text = new string(buffer, offset, charsRead); Console.WriteLine(text); }In this example, we create a TcpClient object and connect to a server. We get the network stream associated with the client and create an instance of the StreamReader class. We read 1024 characters at a time from the network stream using the ReadBlock method and display them on the console. Package library: System.IO.FileSystem.
public ReadBlock ( char buffer, int index, int count ) : int | ||
buffer | char | |
index | int | |
count | int | |
return | int |