public ReadAsync ( char buffer, int index, int count ) : Task |
||
buffer | char | |
index | int | |
count | int | |
return | Task |
using System.IO; using System.Threading.Tasks; public async TaskReadFromFileAsync(string filePath, int bufferSize) { using (var streamReader = new StreamReader(filePath)) { var charBuffer = new char[bufferSize]; var stringBuilder = new StringBuilder(); while(await streamReader.ReadAsync(charBuffer, 0, charBuffer.Length) > 0) { stringBuilder.Append(charBuffer); } return stringBuilder.ToString(); } }
using System.IO; using System.Threading.Tasks; public async TaskThis example demonstrates reading text asynchronously from a NetworkStream object using the StreamReader's ReadAsync method. The method takes in a NetworkStream object and a buffer size as parameters. The text is read from the stream and appended to a StringBuilder object until the end of the stream is reached. The resulting string is then returned. The package library for the System.IO namespace is part of the .NET Core runtime library.ReadFromNetworkStreamAsync(NetworkStream stream, int bufferSize) { using (var streamReader = new StreamReader(stream)) { var charBuffer = new char[bufferSize]; var stringBuilder = new StringBuilder(); while(await streamReader.ReadAsync(charBuffer, 0, charBuffer.Length) > 0) { stringBuilder.Append(charBuffer); } return stringBuilder.ToString(); } }
public ReadAsync ( char buffer, int index, int count ) : Task |
||
buffer | char | |
index | int | |
count | int | |
return | Task |