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

Provides support for creating and using a stream whose backing store is memory.

The class creates streams that have memory as a backing store instead of a disk or a network connection. encapsulates data stored as an unsigned byte array. The encapsulated data is directly accessible in memory. Memory streams can reduce the need for temporary buffers and files in an application.

The of a stream is the position at which the next read or write operation takes 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.

The maximum length of a is implementation-specific.

Memory streams created with an unsigned byte array provide a non-resizable stream view 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.

- Constructor

  Constructs and initializes a new resizable instance of the class.

  The , , and properties of the new instance of the class are set to .

  The capacity of the new stream instance can be increased by using the method or by setting the property.

  The new stream exposes the underlying byte buffer, which can be accessed through the method.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Constructor
  The array from which to create the new stream.

  Constructs and initializes a new non-resizable instance of the class.

  The , , and properties of the new instance of the class are set to . is set to the length of the specified array.

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

  The new stream does not expose the underlying byte buffer, and calls to the method throw .

  The parameter is .
  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Constructor
  A that specifies the initial size of the internal array.

  Constructs and initializes a new resizable instance of the class.

  The , , and properties of the new instance of the class are set to .

  The of the new stream instance is set to can be increased by using the method or by setting the property. Write operations at the end of the new instance of the class expand the .

  The new stream exposes the underlying byte buffer, which can be accessed through the method.

  is negative.
  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Constructor
  The array from which to create the new stream.
  A that specifies whether the new stream instance supports writing.

  Constructs and initializes a new non-resizable instance of the class.

  The and properties of the new instance of the class are set to . The property is set to the length of the specified array. The property is set to .

  The new stream instance can be written to depending on the value of , but the of the underlying array cannot be changed. The length of the stream cannot be set to a value larger than , but the stream can be truncated (see ).

  The new stream does not expose the underlying buffer, and calls to the method throw .

  is .
  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Constructor
  The array from which to create the new stream.
  A that specifies the index into at which the stream begins.
  A that specifies the length of the stream in bytes.

  Constructs and initializes a new non-resizable instance of the class.

  The , , and properties of the new instance are set to . The property is set to .

  The new stream instance can be written to, but the of the underlying array cannot be changed. The length of the stream cannot be set to a value larger than , but the stream can be truncated (see ).

  The new stream does not expose the underlying buffer, and calls to the method throw .

  is .
  or is less than zero.
  ( + ) is greater than the length of .
  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Constructor
  The array from which to create the new stream.
  A that specifies the index in at which the stream begins.
  A that specifies the length of the stream in bytes.
  A that specifies whether the new stream instance supports writing.

  Constructs and initializes a new non-resizable instance of the class.

  The and properties of the new are set to . The property is set to . The property is set to .

  The new stream instance can be written to depending on the value of , but the of the underlying byte array cannot be changed. The length of the stream cannot be set to a value larger than , but the stream can be truncated (see ).

  The new stream does not expose the underlying byte buffer, and calls to the method throw .

  is .
  or are negative.
  ( + ) is greater than the length of .
  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Constructor
  The array from which to create the new stream.
  A that specifies the index into at which the stream begins.
  A that specifies the length of the stream in bytes.
  A that specifies whether the new stream instance supports writing.
  A that specifies whether is exposed via , which returns the array from which the stream was created. Specify to expose ; otherwise, specify .

  Constructs and initializes a new instance of the class.

  The and properties of the new instance are set to . The property is set to . The property is set to .

  The new stream instance can be written to depending on the value of , but the of the underlying array cannot be changed. The length of the stream cannot be set to a value larger than , but the stream can be truncated (see ).

  is .
  or is negative.
  ( + ) is greater than the length of .
  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Property
  System.Boolean

  Gets a value indicating whether the current stream supports reading.

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

  This property is read-only.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Property
  System.Boolean

  Gets a value indicating whether the current stream supports seeking.

  if the stream is open and supports seeking; otherwise .

  This property is read-only.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Property
  System.Boolean

  Gets a value indicating whether the current stream supports writing.

  if the stream supports writing; otherwise, .

  This property is read-only.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Property
  System.Int32

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

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

  is the buffer length for system-provided byte arrays. If the current stream is created with a specified array, indicates the length of the portion of the provided array to which the current stream has access. For additional information, see the ([], , ) constructor.

  cannot be set to a value less than the current length of the stream, but can be set to less than the current capacity. If the capacity specified is less than the current capacity, the size of the buffer used to hold the stream can be reduced, but need not be.

  If the value specified for a set operation is less than the default value, for performance reasons the property is set to the default. The default value of the property is unspecified.

  As described above.

  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. 0 1.0.5000.0 2.0.0.0 4.0.0.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
  2.0.0.0
  4.0.0.0
  System.Void `` To be added. To be added. To be added.
- Method
  System.Void

  Overrides so that no action is performed.

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

  This method overrides .

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Method
  System.Byte[]

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

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

  To create a instance with a publicly visible buffer use the default constructor, ( [], , , , ) or ( ) constructor.

  If the current stream is resizable, multiple calls to this method do not return the same array if the underlying array is resized between calls. For additional information, see .

  This method works when the is closed.

  As described above.

  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.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Property
  System.Int64

  Gets the length of the stream in bytes.

  A containing the length of the stream in bytes.

  This property is read-only.

  This property overrides .

  The current stream is closed. 0 1.0.5000.0 2.0.0.0 4.0.0.0
- Method
  4.0.0.0
  System.Void To be added. To be added.
- Property
  System.Int64

  Gets or sets the current position within the stream.

  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. 0 1.0.5000.0 2.0.0.0 4.0.0.0
- Method
  System.Int32 `` `` `` A array. When this method returns, contains the specified byte array with the values between and replaced by the characters read from the current stream. A that specifies the byte offset in at which to begin writing. A that specifies the maximum number of bytes to read.

  Reads a block of bytes from the current stream at the current position, and writes the data to the specified byte array.

  A that specifies the total number of bytes written into the buffer, or zero if the end of the stream is reached before any bytes are read.

  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.

  If the read takes place immediately following a seek beyond the end of the stream, the end of the stream is reached.

  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.

  This method overrides .

  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

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Method
  System.Int32

  Reads a byte from the current stream at the current position.

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

  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.

  If the read takes place immediately following a seek beyond the end of the stream, the end of the stream is reached.

  This method overrides .

  The current stream is closed. 0 1.0.5000.0 2.0.0.0 4.0.0.0
- Method
  System.Int64 `` `` A that specifies the new position within the stream. This is relative to the parameter, and can be positive or negative. A value that specifies the seek reference point.

  Changes the position within the current stream by the given offset, which is relative to the stated origin.

  A containing the new position within the stream, calculated by combining the seek reference point and the offset.

  This method overrides .

  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. 0 1.0.5000.0 2.0.0.0 4.0.0.0
- Method
  System.Void `` A that specifies the value at which to set the length.

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

  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 .

  This method overrides .

  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. 0 1.0.5000.0 2.0.0.0 4.0.0.0
- Method
  System.Byte[]

  Writes the entire stream contents to a array, regardless of the current position within the stream.

  A new array.

  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 the current instance has access is returned. For additional information, see the ([], , ) constructor.

  This method works when the is closed.

  As described above.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Method
  System.Void `` `` `` The array to write data from. A that specifies the zero based byte offset into at which to begin writing from. A that specifies the maximum number of bytes to write from .

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

  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.

  If the write takes place immediately following a seek beyond the end of the stream, that stream is zero-byte-extended to the new seek position before the given bytes are written.

  Write operations at the end of a resizable expand the .

  Use the method to determine whether the current stream supports writing.

  This method overrides .

  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. 0 1.0.5000.0 2.0.0.0 4.0.0.0
- Method
  System.Void `` The to write.

  Writes a to the current stream at the current position.

  Write operations at the end of a resizable expand the . If the write operation is successful, the current position within the stream is advanced by one byte. If an exception occurs, the position is unchanged.

  If the write takes place immediately following a seek beyond the end of the stream, that stream is zero-byte-extended to the new seek position before the given byte is written.

  Use the method to determine whether the current stream supports writing.

  This method overrides .

  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.

  0
  1.0.5000.0
  2.0.0.0
  4.0.0.0
- Method
  System.Void `` The to write the current memory stream to.

  Writes the entire contents of the current instance to a specified stream.

  This method is equivalent to calling and passing in the underlying buffer of the current instance.

  As described above.

  is . The current or target stream is closed. 0 1.0.5000.0 2.0.0.0 4.0.0.0
0 System.Runtime.InteropServices.ComVisible(true)