Mono Class Library: System.IO.MemoryStream Overview | MembersSystem.IO.MemoryStream.SetLength Method |
Sets the length of the current stream to the specified value. [Edit]
|
Type Reason NotSupportedException The current stream is not resizable and value is greater than the current MemoryStream.Capacity.
-or-
The current stream does not support writing.
[Edit]ArgumentOutOfRangeException value is negative or is greater than the maximum length of the System.IO.MemoryStream - origin, where origin is the index into the underlying buffer at which the stream starts. [Edit]
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 MemoryStream.ReadByte method returns -1, the MemoryStream.Read(Byte[], int, int) method reads zero bytes into the provided byte array, and MemoryStream.Write(Byte[], int, int) and MemoryStream.WriteByte(byte) 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.
Note:[Edit]A System.IO.MemoryStream instance must support writing for this method to work. Use the MemoryStream.CanWrite property to determine whether the current instance supports writing. For additional information, see Stream.CanWrite .
This method overrides Stream.SetLength(long).
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0