The MemoryStream class provides a way to write binary data directly to memory, avoiding the overhead of a file stream.
Description
The MemoryStream class implements the System.IO.MemoryStream interface. It’s useful when you need to process data in memory without writing to a physical file.
Usage
You can use MemoryStream to buffer binary data for operations such as:
- Reading and writing binary data
- Creating compressed files
- Sending data over a network
Example
using System.IO;
// ...
using (MemoryStream ms = new MemoryStream()) {
byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
ms.Write(data, 0, data.Length);
// ...
}