MemoryStream 建構函式

定義

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

多載

名稱 Description
MemoryStream()

初始化一個可擴充容量為零的類別新實例 MemoryStream

MemoryStream(Byte[])

根據指定的位元組陣列初始化一個新的不可調整大小的 MemoryStream 類別實例。

MemoryStream(Int32)

初始化一個類別的新實例 MemoryStream ,並依規定初始化可擴充容量。

MemoryStream(Byte[], Boolean)

根據指定的位元組陣列初始化一個新的不可調整大小的類別實例 MemoryStream ,並設定 CanWrite 了該屬性。

MemoryStream(Byte[], Int32, Int32)

根據指定的位元組陣列區域(索引)初始化該 MemoryStream 類別的新且不可調整大小的實例。

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

根據指定區域的位元組陣列初始化一個新的不可調整大小類別實例 MemoryStream ,並設定 CanWrite 相應的屬性。

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

根據指定區域的位元組陣列初始化該類別的新 MemoryStream 實例,屬性 CanWrite 設定如指定,並能呼叫 GetBuffer() set。

MemoryStream()

來源:
MemoryStream.cs
來源:
MemoryStream.cs
來源:
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.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.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 為負數。

-或-

在.NET 11及以後版本中,capacity 大於 Array.MaxLength

範例

此程式碼範例是本類別更大範例 MemoryStream 的一部分。

using(MemoryStream memStream = new MemoryStream(100))
Dim memStream As New MemoryStream(100)

備註

這些 CanReadCanSeekCanWrite 屬性都設為 true

當你用這個 SetLength 方法將長度設定為大於當前流容量的值時,容量會自動增加。 除了構造中帶有位元組[]參數外,將MemoryStream寫入在展開MemoryStream的末尾MemoryStream的操作。

這個建構子會暴露回 GetBuffer 傳的底層串流。

另請參閱

適用於

MemoryStream(Byte[], Boolean)

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

根據指定的位元組陣列初始化一個新的不可調整大小的類別實例 MemoryStream ,並設定 CanWrite 了該屬性。

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

備註

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

串流長度不能設定為大於指定位元組初始長度的值;然而,串流可以被截斷(參見 SetLength)。

此構造器不會暴露底層的串流。 GetBuffer 投擲 UnauthorizedAccessException

另請參閱

適用於

MemoryStream(Byte[], Int32, Int32)

來源:
MemoryStream.cs
來源:
MemoryStream.cs
來源:
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.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

備註

CanReadCanSeek屬性都設為 trueCapacity 設定為 count

串流長度不能設定為大於指定位元組初始長度的值;然而,串流可以被截斷(參見 SetLength)。

此構造器不會暴露底層的串流。 GetBuffer 投擲 UnauthorizedAccessException。 然而,如果 writable 是 , true你可以寫入串流。

另請參閱

適用於

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

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

根據指定區域的位元組陣列初始化該類別的新 MemoryStream 實例,屬性 CanWrite 設定如指定,並能呼叫 GetBuffer() set。

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

true啟用 GetBuffer(),回傳產生串流的無符號位元組陣列;否則,。 false

例外狀況

buffernull

indexcount 是陰性。

緩衝區長度減 index 值小於 count

備註

CanReadCanSeek屬性都設為 trueCapacity 設定為 count

新的串流實例可以寫入,但底層位元組陣列的 S Capacity 無法被更改。 串流長度不能設定為大於指定位元組初始長度的值;然而,串流可以被截斷(參見 SetLength)。

另請參閱

適用於