ストリームに割り当てられたバイト数を取得または設定します。
Public Overridable Property Capacity As Integer
[C#]
public virtual int Capacity {get; set;}
[C++]
public: __property virtual int get_Capacity();public: __property virtual void set_Capacity(int);
[JScript]
public function get Capacity() : int;public function set Capacity(int);
プロパティ値
ストリームに対してバッファが使用できる部分の長さ。
例外
例外の種類 | 条件 |
---|---|
ArgumentOutOfRangeException | 容量が負の値または現在のストリーム長より小さい値に設定されています。 |
ObjectDisposedException | 現在のストリームが閉じています。 |
NotSupportedException | 容量を変更できないストリームに対して set が呼び出されました。 |
解説
ファイルの作成およびテキストのファイルへの書き込みの例については、「 ファイルへのテキストの書き込み 」を参照してください。ファイルからのテキストの読み取りの例については、「 ファイルからのテキストの読み取り 」を参照してください。バイナリ ファイルからの読み取りおよびバイナリ ファイルへの書き込みの例については、「 新しく作成したデータ ファイルの読み取りと書き込み 」を参照してください。
Capacity は、システムが提供するバイト配列のバッファ長です。 Capacity は現在のストリーム長より小さい値には設定できません。
使用例
[Visual Basic, C#, C++] 次のコード例は MemoryStream クラスの例の一部です。
' Write the stream properties to the console.
Console.WriteLine( _
"Capacity = {0}, Length = {1}, Position = {2}", _
memStream.Capacity.ToString(), _
memStream.Length.ToString(), _
memStream.Position.ToString())
[C#]
// 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());
[C++]
// Write the stream properties to the console.
Console::WriteLine(S"Capacity = {0}, Length = {1}, "
S"Position = {2}\n", memStream->Capacity.ToString(),
memStream->Length.ToString(),
memStream->Position.ToString());
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
MemoryStream クラス | MemoryStream メンバ | System.IO 名前空間 | 入出力操作 | ファイルからのテキストの読み取り | ファイルへのテキストの書き込み