byte[] data = Encoding.UTF8.GetBytes("Hello world"); using (MemoryStream stream = new MemoryStream(data)) { StreamReader reader = new StreamReader(stream); string result = reader.ReadToEnd(); Console.WriteLine(result); }This example creates a new memory stream from a byte array containing the string "Hello world", creates a stream reader from the memory stream, and calls the ReadToEnd method to read the string from the memory stream. The resulting string is then printed to the console. This method is commonly used to read the contents of a file or network stream into memory as a string or byte array. The System.IO namespace is included with the .NET Framework and does not require any additional packages or libraries.