byte[] data = { 1, 2, 3, 4, 5 }; MemoryStream stream = new MemoryStream(data); // write some data to the stream stream.WriteByte(6); // flush the buffer to write all data to the stream stream.Flush();In this example, we create a MemoryStream object and write some data to it using the WriteByte method. We then call the Flush method to ensure that all the data is written to the underlying memory. Package library: System.IO.MemoryStream is part of the System.IO namespace in the .NET Class Library.