Mono Class Library: System.IO.MemoryStream Overview | Members

System.IO.MemoryStream.SetLength Method

Sets the length of the current stream to the specified value. [Edit]

public override void SetLength (long value)

Parameters

value
A long that specifies the value at which to set the length. [Edit]

Exceptions

TypeReason
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]
ArgumentOutOfRangeExceptionvalue 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]

Remarks

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:

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).

[Edit]

Requirements

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