MemoryStream 建構函式

定義

初始化 MemoryStream 類別的新執行個體。

多載

MemoryStream()

使用初始化為零的可擴展容量,初始化 MemoryStream 類別的新執行個體。

MemoryStream(Byte[])

根據指定的位元組陣列,初始化 MemoryStream 類別之不可調整大小的執行個體。

MemoryStream(Int32)

使用初始化為指定的可擴展容量,初始化 MemoryStream 類別的新執行個體。

MemoryStream(Byte[], Boolean)

根據具有指定的 CanWrite 屬性設定之位元組陣列,來初始化 MemoryStream 類別之新的不可調整大小的執行個體。

MemoryStream(Byte[], Int32, Int32)

根據位元組陣列的指定區域 (索引),來初始化 MemoryStream 類別之新的不可調整大小的執行個體。

MemoryStream(Byte[], Int32, Int32, Boolean)

根據位元組陣列的指定區域 (且該區域使用依指定所設定的 MemoryStream 屬性),來初始化 CanWrite 類別之新的不可調整大小的執行個體。

MemoryStream(Byte[], Int32, Int32, Boolean, Boolean)

根據指定的位元組陣列區域 (且該區域使用依指定所設定的 MemoryStream 屬性和依指定所設定的呼叫 CanWrite 的能力),來初始化 GetBuffer() 類別的新執行個體。

MemoryStream()

來源:
MemoryStream.cs
來源:
MemoryStream.cs
來源:
MemoryStream.cs

使用初始化為零的可擴展容量,初始化 MemoryStream 類別的新執行個體。

public:
 MemoryStream();
public MemoryStream ();
Public Sub New ()

備註

CanReadCanSeekCanWrite 屬性全都設定為 true

當您使用 SetLength 方法將長度設定為大於目前數據流容量的值時,目前數據流的容量會自動增加。

此建構函式會公開傳回的基礎數據流 GetBuffer

另請參閱

適用於

MemoryStream(Byte[])

來源:
MemoryStream.cs
來源:
MemoryStream.cs
來源:
MemoryStream.cs

根據指定的位元組陣列,初始化 MemoryStream 類別之不可調整大小的執行個體。

public:
 MemoryStream(cli::array <System::Byte> ^ buffer);
public MemoryStream (byte[] buffer);
new System.IO.MemoryStream : byte[] -> System.IO.MemoryStream
Public Sub New (buffer As Byte())

參數

buffer
Byte[]

用於建立目前資料流之不帶正負號位元組的陣列。

例外狀況

buffernull

備註

CanReadCanSeekCanWrite 屬性全都設定為 trueCapacity 設定為指定位元組陣列的長度。 新的數據流可以寫入,但無法重設大小。

數據流長度不能設定為大於指定位元組陣列之初始長度的值;不過,數據流可以截斷 (請參閱 SetLength) 。

此建構函式不會公開基礎數據流。 GetBuffer 會擲回 UnauthorizedAccessException

另請參閱

適用於

MemoryStream(Int32)

來源:
MemoryStream.cs
來源:
MemoryStream.cs
來源:
MemoryStream.cs

使用初始化為指定的可擴展容量,初始化 MemoryStream 類別的新執行個體。

public:
 MemoryStream(int capacity);
public MemoryStream (int capacity);
new System.IO.MemoryStream : int -> System.IO.MemoryStream
Public Sub New (capacity As Integer)

參數

capacity
Int32

內部陣列的初始大小,以位元組為單位。

例外狀況

capacity 為負。

範例

此程式代碼範例是提供給 類別之較大範例的 MemoryStream 一部分。

MemoryStream^ memStream = gcnew MemoryStream( 100 );
using(MemoryStream memStream = new MemoryStream(100))
Dim memStream As New MemoryStream(100)

備註

CanReadCanSeekCanWrite 屬性全都設定為 true

當您使用 SetLength 方法將長度設定為大於目前數據流容量的值時,容量會自動增加。 MemoryStream除了使用 byte[] 參數建構的 之外,在展開 MemoryStream結尾的MemoryStream寫入作業。

此建構函式會公開傳 GetBuffer 回的基礎數據流。

另請參閱

適用於

MemoryStream(Byte[], Boolean)

來源:
MemoryStream.cs
來源:
MemoryStream.cs
來源:
MemoryStream.cs

根據具有指定的 CanWrite 屬性設定之位元組陣列,來初始化 MemoryStream 類別之新的不可調整大小的執行個體。

public:
 MemoryStream(cli::array <System::Byte> ^ buffer, bool writable);
public MemoryStream (byte[] buffer, bool writable);
new System.IO.MemoryStream : byte[] * bool -> System.IO.MemoryStream
Public Sub New (buffer As Byte(), writable As Boolean)

參數

buffer
Byte[]

用於建立這個資料流之不帶正負號位元組的陣列。

writable
Boolean

CanWrite 屬性的設定,決定資料流是否支援寫入。

例外狀況

buffernull

備註

CanRead屬性 CanSeek 都設定為 trueCapacity 設定為指定位元組陣列的長度。

數據流長度不能設定為大於指定位元組陣列之初始長度的值;不過,數據流可以截斷 (請參閱 SetLength) 。

此建構函式不會公開基礎數據流。 GetBuffer 會擲回 UnauthorizedAccessException

另請參閱

適用於

MemoryStream(Byte[], Int32, Int32)

來源:
MemoryStream.cs
來源:
MemoryStream.cs
來源:
MemoryStream.cs

根據位元組陣列的指定區域 (索引),來初始化 MemoryStream 類別之新的不可調整大小的執行個體。

public:
 MemoryStream(cli::array <System::Byte> ^ buffer, int index, int count);
public MemoryStream (byte[] buffer, int index, int count);
new System.IO.MemoryStream : byte[] * int * int -> System.IO.MemoryStream
Public Sub New (buffer As Byte(), index As Integer, count As Integer)

參數

buffer
Byte[]

用於建立這個資料流之不帶正負號位元組的陣列。

index
Int32

buffer 中資料流開始處的索引。

count
Int32

資料流的長度,以位元組為單位。

例外狀況

buffernull

indexcount 小於零。

緩衝區長度減去 index 會小於 count

備註

CanReadCanSeekCanWrite 屬性全都設定為 true,但無法變更容量。 Capacity 設定為 count

數據流長度不能設定為大於指定位元組陣列之初始長度的值;不過,數據流可以截斷 (請參閱 SetLength) 。

此建構函式不會公開基礎數據流。 GetBuffer 會擲回 UnauthorizedAccessException。 不過,您可以寫入數據流。

另請參閱

適用於

MemoryStream(Byte[], Int32, Int32, Boolean)

來源:
MemoryStream.cs
來源:
MemoryStream.cs
來源:
MemoryStream.cs

根據位元組陣列的指定區域 (且該區域使用依指定所設定的 MemoryStream 屬性),來初始化 CanWrite 類別之新的不可調整大小的執行個體。

public:
 MemoryStream(cli::array <System::Byte> ^ buffer, int index, int count, bool writable);
public MemoryStream (byte[] buffer, int index, int count, bool writable);
new System.IO.MemoryStream : byte[] * int * int * bool -> System.IO.MemoryStream
Public Sub New (buffer As Byte(), index As Integer, count As Integer, writable As Boolean)

參數

buffer
Byte[]

用於建立這個資料流之不帶正負號位元組的陣列。

index
Int32

buffer 中資料流開始處的索引。

count
Int32

資料流的長度,以位元組為單位。

writable
Boolean

CanWrite 屬性的設定,決定資料流是否支援寫入。

例外狀況

buffernull

indexcount 為負值。

緩衝區長度減去 index 會小於 count

備註

CanRead屬性 CanSeek 都設定為 trueCapacity 設定為 count

數據流長度不能設定為大於指定位元組陣列之初始長度的值;不過,數據流可以截斷 (請參閱 SetLength) 。

此建構函式不會公開基礎數據流。 GetBuffer 會擲回 UnauthorizedAccessException。 不過,如果 為 writabletrue,您可以寫入數據流。

另請參閱

適用於

MemoryStream(Byte[], Int32, Int32, Boolean, Boolean)

來源:
MemoryStream.cs
來源:
MemoryStream.cs
來源:
MemoryStream.cs

根據指定的位元組陣列區域 (且該區域使用依指定所設定的 MemoryStream 屬性和依指定所設定的呼叫 CanWrite 的能力),來初始化 GetBuffer() 類別的新執行個體。

public:
 MemoryStream(cli::array <System::Byte> ^ buffer, int index, int count, bool writable, bool publiclyVisible);
public MemoryStream (byte[] buffer, int index, int count, bool writable, bool publiclyVisible);
new System.IO.MemoryStream : byte[] * int * int * bool * bool -> System.IO.MemoryStream
Public Sub New (buffer As Byte(), index As Integer, count As Integer, writable As Boolean, publiclyVisible As Boolean)

參數

buffer
Byte[]

用於建立這個資料流之不帶正負號位元組的陣列。

index
Int32

buffer 中資料流開始處的索引。

count
Int32

資料流的長度,以位元組為單位。

writable
Boolean

CanWrite 屬性的設定,決定資料流是否支援寫入。

publiclyVisible
Boolean

啟用 GetBuffer() (傳回從其中建立資料流的不帶正負號的位元組陣列),則為 true;否則為 false

例外狀況

buffernull

indexcount 為負。

緩衝區長度減去 index 會小於 count

備註

CanRead屬性 CanSeek 都設定為 trueCapacity 設定為 count

新的資料串流實例可以寫入至 ,但 Capacity 無法變更基礎位元組數組的 。 數據流的長度不能設定為大於指定位元組陣列的初始長度的值;不過, (請參閱 SetLength) 截斷數據流。

另請參閱

適用於