byte[] buffer = { 10, 20, 30, 40, 50 }; MemoryStream stream = new MemoryStream(); stream.Write(buffer, 0, buffer.Length);
byte[] buffer = new byte[5]; MemoryStream stream = new MemoryStream(); stream.WriteByte(10); stream.WriteByte(20); stream.WriteByte(30); stream.WriteByte(40); stream.WriteByte(50); stream.Position = 0; stream.Read(buffer, 0, buffer.Length);In this example, we create a byte array and a memory stream object. We then write individual bytes to the memory stream and read them back into the byte array. Package library: System.IO.MemoryStream is a part of the .NET Framework, which contains a large collection of classes that can be used for developing applications on Windows.