BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.IO.Stream System.Runtime.InteropServices.ComVisible(true)

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 method. When a new instance of 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 object is added to a ResX file or a .resources file, call the method at runtime to retrieve it.

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

Creates a stream whose backing store is memory.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  The , , and properties are all set to true.

  The capacity of the current stream automatically increases when you use the method to set the length to a value larger than the capacity of the current stream.

  This constructor exposes the underlying stream, which returns.

  Initializes a new instance of the class with an expandable capacity initialized to zero.

  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  The parameter is .

  The , , and properties are all set to true. is set to the length of the specified byte array. The new stream can be written to, but is not resizable.

  The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see ).

  This constructor does not expose the underlying stream. throws .

  Initializes a new non-resizable instance of the class based on the specified byte array.

  The array of unsigned bytes from which to create the current stream.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  is negative.

  The , , and properties are all set to true.

  The capacity automatically increases when you use the method to set the length to a value larger than the capacity of the current stream. Except for a MemoryStream constructed with a byte[] parameter, write operations at the end of a MemoryStream expand the MemoryStream.

  This constructor exposes the underlying stream that returns.

  Initializes a new instance of the class with an expandable capacity initialized as specified.

  The initial size of the internal array in bytes.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  is .

  The and properties are both set to true. is set to the length of the specified byte array.

  The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see ).

  This constructor does not expose the underlying stream. throws .

  Initializes a new non-resizable instance of the class based on the specified byte array with the property set as specified.

  The array of unsigned bytes from which to create this stream.
  The setting of the property, which determines whether the stream supports writing.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  is .
  or is less than zero.
  ( + ) is greater than the length of .

  The , , and properties are all set to true, but the capacity cannot be changed. is set to .

  The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see ).

  This constructor does not expose the underlying stream. throws . However, you can write to the stream.

  Initializes a new non-resizable instance of the class based on the specified region (index) of a byte array.

  The array of unsigned bytes from which to create this stream.
  The index into at which the stream begins.
  The length of the stream in bytes.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  is .
  or are negative.
  ( + ) is greater than the length of .

  The and properties are both set to true. is set to .

  The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see ).

  This constructor does not expose the underlying stream. throws . However, you can write to the stream if is true.

  Initializes a new non-resizable instance of the class based on the specified region of a byte array, with the property set as specified.

  The array of unsigned bytes from which to create this stream.
  The index in at which the stream begins.
  The length of the stream in bytes.
  The setting of the property, which determines whether the stream supports writing.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  is .
  or is negative.
  ( + ) is greater than the length of .

  The and properties are both set to true. is set to .

  The new stream instance can be written to, but the of the underlying byte array cannot be changed. The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see ).

  Initializes a new instance of the class based on the specified region of a byte array, with the property set as specified, and the ability to call set as specified.

  The array of unsigned bytes from which to create this stream.
  The index into at which the stream begins.
  The length of the stream in bytes.
  The setting of the property, which determines whether the stream supports writing.
  true to enable , which returns the unsigned byte array from which the stream was created; otherwise, false.
  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean

  if the current stream is open and supports reading; otherwise .

  If a class derived from does not support reading, calls to the and methods throw a .

  If the stream is closed, this property returns false.

  Gets a value indicating whether the current stream supports reading.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean

  if the stream is open and supports seeking; otherwise .

  If a class derived from does not support seeking, calls to , , , and throw a .

  If the stream is closed, this property returns false.

  Gets a value indicating whether the current stream supports seeking.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean

  if the stream supports writing; otherwise, .

  If a class derived from does not support writing, a call to , , or throws a .

  If the stream is closed, this property returns false.

  Gets a value indicating whether the current stream supports writing.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32

  A containing the number of bytes allocated for the current stream.

  The value specified for a set operation is negative or less than the current length of the stream. A set operation was attempted on a stream whose capacity cannot be modified. The current stream is closed.

  Capacity is the buffer length for system-provided byte arrays. Capacity cannot be set to a value less than the current length of the stream.

  Gets or sets the number of bytes allocated for this stream.

  0
- Method
  System.Void

  Closes the current instance.

  The stream will not support reading or writing after this method is invoked. Following a call to , operations on the stream can raise an exception.

  The buffer of a closed is still available, and the and methods can be called successfully.

  This method overrides . 0 1.0.5000.0
- Method
  4.0.0.0
  System.Threading.Tasks.Task `` `` `` To be added.

  Asynchronously reads all the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token.

  A task that represents the asynchronous copy operation.

  The stream to which the contents of the current stream will be copied. The size, in bytes, of the buffer. This value must be greater than zero. The token to monitor for cancellation requests.
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  This method is called by the public method and the method. invokes the protected method with the parameter set to true. invokes with set to false.

  When the parameter is true, this method releases all resources held by any managed objects that this references. This method invokes the method of each referenced object.

  Releases the unmanaged resources used by the class and optionally releases the managed resources.

  true to release both managed and unmanaged resources; false to release only unmanaged resources.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void

  This method overrides the method.

  Because any data written to a object is written into RAM, this method is redundant.

  Overrides the method so that no action is performed.

  0
- Method
  4.0.0.0
  System.Threading.Tasks.Task ``

  Because any data written to a object is written into RAM, this method is redundant.

  If the operation is canceled before it completes, the returned task contains the value for the property.

  You can create a cancellation token by creating an instance of the class and passing the property as the parameter.

  Asynchronously clears all buffers for this stream, and monitors cancellation requests.

  A task that represents the asynchronous flush operation.

  The token to monitor for cancellation requests.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Byte[] The current instance was not created with a publicly visible buffer.

  The following example demonstrates that two calls to the method on a resizable stream do not return the same array if the underlying byte array is reallocated.

  `using System; using System.IO; public class MemoryStreamTest { public static void Main() { MemoryStream ms = new MemoryStream(10); byte[] a = ms.GetBuffer(); byte[] b = ms.GetBuffer(); //Force reallocation of the underlying byte array. ms.Capacity = 10240; byte[] c = ms.GetBuffer(); if(Object.ReferenceEquals(a, b)) Console.WriteLine("a and b represent the same instance."); else Console.WriteLine("a and b represent the different instances."); if(Object.ReferenceEquals(a, c)) Console.WriteLine("a and c represent the same instance."); else Console.WriteLine("a and c represent the different instances."); } }`

  The output is

  a and b represent the same instance.

  a and c represent the different instances.

  Note that the buffer contains allocated bytes which might be unused. For example, if the string "test" is written into the object, the length of the buffer returned from is 256, not 4, with 252 bytes unused. To obtain only the data in the buffer, use the method; however, creates a copy of the data in memory.

  The buffer can also be null.

  To create a MemoryStream instance with a publicly visible buffer, use , , or . If the current stream is resizable, two calls to this method do not return the same array if the underlying byte array is resized between calls. For additional information, see .

  This method works when the memory stream is closed.

  Returns the array of unsigned bytes from which this stream was created.

  The byte array from which this stream was created, or the underlying array if a byte array was not provided to the constructor during construction of the current instance.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int64

  A containing the length of the stream in bytes.

  This property is read-only.

  This property overrides .

  The current stream is closed.

  Gets the length of the stream in bytes.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int64

  A containing the current position within the stream.

  This property overrides .

  The value specified for a set operation is negative or greater than the maximum length of a . The current stream is closed.

  Gets or sets the current position within the stream.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 `` `` `` is . or is negative. ( + ) is larger than the length of . The current stream is closed.

  The following example demonstrates the result of reading from a into its underlying byte array.

  `using System; using System.IO; public class MemoryStreamTest { public static void Main() { byte[] values = new byte [] {0,1,2,3,4,5,6,7,8,9}; foreach (byte b in values) { Console.Write(b); } Console.WriteLine(); MemoryStream ms = new MemoryStream (values); ms.Read(values, 1, 5); foreach (byte b in values) { Console.Write(b); } } }`

  The output is

  0123456789

  0012346789

  This method overrides .

  The parameter gives the offset of the first byte in to which data from the current stream is written. The parameter gives the maximum number of bytes to read from the current stream. The returned value is the actual number of bytes read, or zero if the end of the stream is reached.

  If the read operation is successful, the current position within the stream advances by the number of bytes read. If an exception occurs, the current position within the stream remains unchanged.

  The Read method will return zero only if the end of the stream is reached. In all other cases, Read always reads at least one byte from the stream before returning. By definition, if no data is available from the stream upon a call to Read, the Read method returns zero (the end of the stream is reached automatically). An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached.

  Use for reading primitive data types.

  If the byte array specified in the parameter is the underlying buffer returned by the method, the array contents are overwritten, and no exception is thrown.

  Reads a block of bytes from the current stream and writes the data to a buffer.

  The total number of bytes written into the buffer. This can be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached before any bytes are read.

  When this method returns, contains the specified byte array with the values between and ( + - 1) replaced by the characters read from the current stream. The zero-based byte offset in at which to begin storing data from the current stream. The maximum number of bytes to read. 0
- Method
  4.0.0.0
  System.Threading.Tasks.Task<System.Int32> `` `` `` ``

  If the operation is canceled before it completes, the returned task contains the value for the property.

  You can create a cancellation token by creating an instance of the class and passing the property as the parameter.

  Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

  A task that represents the asynchronous read operation. The value of the parameter contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.

  The buffer to write the data into. The byte offset in at which to begin writing data from the stream. The maximum number of bytes to read. The token to monitor for cancellation requests. The default value is .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32 The current stream is closed.

  This method overrides .

  If the read operation is successful, the current position within the stream is advanced by one byte. If an exception occurs, the current position within the stream is unchanged.

  Reads a byte from the current stream.

  The byte cast to a , or -1 if the end of the stream has been reached.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int64 `` `` Seeking is attempted before the beginning of the stream. is greater than the maximum length of . is not a valid value. The current stream is closed.

  This method overrides .

  Seeking to any location beyond the length of the stream is supported.

  Do not use the method to determine the new position in the stream if the was initialized with a non-zero offset. If you do, will return an inaccurate value. Instead, use the property to get the new position of the stream.

  Sets the position within the current stream to the specified value.

  The new position within the stream, calculated by combining the initial reference point and the offset.

  The new position within the stream. This is relative to the parameter, and can be positive or negative. A value of type , which acts as the seek reference point. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void ``

  The current stream is not resizable and is greater than the current .

  -or-

  The current stream does not support writing.

  is negative or is greater than the maximum length of the - , where is the index into the underlying buffer at which the stream starts.

  This method overrides .

  If the specified value is less than the current length of the stream, the stream is truncated. If after the truncation the current position within the stream is past the end of the stream, the method returns -1, the method reads zero bytes into the provided byte array, and and methods append specified bytes at the end of the stream, increasing its length. If the specified value is larger than the current capacity and the stream is resizable, the capacity is increased, and the current position within the stream is unchanged. If the length is increased, the contents of the stream between the old and the new length are initialized to zeros.

  A instance must support writing for this method to work. Use the property to determine whether the current instance supports writing. For additional information, see .

  Sets the length of the current stream to the specified value.

  The value at which to set the length. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Byte[]

  This method omits unused bytes in from the array. To get the entire buffer, use the method.

  This method returns a copy of the contents of the as a byte array. If the current instance was constructed on a provided byte array, a copy of the section of the array to which this instance has access is returned. See the constructor for details.

  This method works when the is closed.

  Writes the stream contents to a byte array, regardless of the property.

  A new byte array.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` `` is .

  The current stream does not support writing.

  -or-

  The current position is closer than bytes to the end of the stream, and the capacity cannot be modified.

  (+ ) is greater than the length of . or are negative. An I/O error occurred. The current stream is closed.

  This method overrides .

  The parameter gives the offset of the first byte in to write from, and the parameter gives the number of bytes to write. If the write operation is successful, the current position within the stream is advanced by the number of bytes written. If an exception occurs, the current position within the stream is unchanged.

  Except for a MemoryStream constructed with a byte[] parameter, write operations at the end of a MemoryStream expand the MemoryStream.

  Writes a block of bytes to the current stream using data read from a buffer.

  The buffer to write data from. The zero-based byte offset in at which to begin copying bytes to the current stream. The maximum number of bytes to write. 0
- Method
  4.0.0.0
  System.Threading.Tasks.Task `` `` `` ``

  If the operation is canceled before it completes, the returned task contains the value for the property.

  You can create a cancellation token by creating an instance of the class and passing the property as the parameter.

  Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

  A task that represents the asynchronous write operation.

  The buffer to write data from. The zero-based byte offset in from which to begin copying bytes to the stream. The maximum number of bytes to write. The token to monitor for cancellation requests. The default value is .
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` The current stream is closed.

  The current stream does not support writing.

  -or-

  The current position is at the end of the stream, and the stream's capacity cannot be modified.

  This method overrides .

  Except for a MemoryStream constructed with a byte[] parameter, write operations at the end of a MemoryStream expand the MemoryStream.

  Writes a byte to the current stream at the current position.

  The byte to write. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` is . The current or target stream is closed.

  When the current stream is open, this method is equivalent to calling on the underlying buffer of this stream.

  Writes the entire contents of this memory stream to another stream.

  The stream to write this memory stream to. 0
0