System.IO.MemoryStream Class

Creates a stream whose backing store is memory.

See Also: MemoryStream Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
public class MemoryStream : Stream

Remarks

The current position of a stream is the position at which the next read or write operation could take place. The current position can be retrieved or set through the MemoryStream.Seek(long, SeekOrigin) method. When a new instance of System.IO.MemoryStream is created, the current position is set to zero.

Memory streams created with an unsigned byte array provide a non-resizable stream of the data. When using a byte array, you can neither append to nor shrink the stream, although you might be able to modify the existing contents depending on the parameters passed into the constructor. Empty memory streams are resizable, and can be written to and read from.

If a System.IO.MemoryStream object is added to a ResX file or a .resources file, call the System.Resources.ResourceManager.GetStream(string) method at runtime to retrieve it.

If a System.IO.MemoryStream object is serialized to a resource file it will actually be serialized as an System.IO.UnmanagedMemoryStream. This behavior provides better performance, as well as the ability to get a pointer to the data directly, without having to go through System.IO.Stream methods.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0