MemoryStream.Capacity 属性

定义

获取或设置分配给该流的字节数。Gets or sets the number of bytes allocated for this stream.

public:
 virtual property int Capacity { int get(); void set(int value); };
public virtual int Capacity { get; set; }
member this.Capacity : int with get, set
Public Overridable Property Capacity As Integer

属性值

流的缓冲区的可使用部分的长度。The length of the usable portion of the buffer for the stream.

异常

容量设置为负或小于流的当前长度。A capacity is set that is negative or less than the current length of the stream.

当前流已关闭。The current stream is closed.

对不能修改其容量的流调用 setset is invoked on a stream whose capacity cannot be modified.

示例

此代码示例是为 MemoryStream 类提供的更大示例的一部分。This code example is part of a larger example provided for the MemoryStream class.

// Write the stream properties to the console.
Console::WriteLine( "Capacity = {0}, Length = {1}, "
"Position = {2}\n", memStream->Capacity.ToString(), memStream->Length.ToString(), memStream->Position.ToString() );
// Write the stream properties to the console.
Console.WriteLine(
    "Capacity = {0}, Length = {1}, Position = {2}\n",
    memStream.Capacity.ToString(),
    memStream.Length.ToString(),
    memStream.Position.ToString());
' Write the stream properties to the console.
Console.WriteLine( _
    "Capacity = {0}, Length = {1}, Position = {2}", _
    memStream.Capacity.ToString(), _
    memStream.Length.ToString(), _
    memStream.Position.ToString())

注解

Capacity 是系统提供的字节数组的缓冲区长度。Capacity is the buffer length for system-provided byte arrays. 不能将 Capacity 设置为小于流的当前长度的值。Capacity cannot be set to a value less than the current length of the stream.

适用于

另请参阅