C# Simple Stream Conversion

Date: 2021-06-10
// convert string to stream
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter( stream );
writer.Write( test );
writer.Flush();

// convert stream to string
stream.Position = 0;
StreamReader reader = new StreamReader( stream );
string text = reader.ReadToEnd();


public static Task<string> ReadStream(Stream stream) 
{
    stream.Position = 0;
    using var reader = new StreamReader(stream);
    return reader.ReadToEndAsync();
}
51160cookie-checkC# Simple Stream Conversion