MemoryStream 建構函式

定義

初始化 MemoryStream 類別的新執行個體。Initializes a new instance of the MemoryStream class.

多載

MemoryStream()

使用初始化為零的可擴展容量,初始化 MemoryStream 類別的新執行個體。Initializes a new instance of the MemoryStream class with an expandable capacity initialized to zero.

MemoryStream(Byte[])

根據指定的位元組陣列,初始化 MemoryStream 類別之不可調整大小的執行個體。Initializes a new non-resizable instance of the MemoryStream class based on the specified byte array.

MemoryStream(Int32)

使用初始化為指定的可擴展容量,初始化 MemoryStream 類別的新執行個體。Initializes a new instance of the MemoryStream class with an expandable capacity initialized as specified.

MemoryStream(Byte[], Boolean)

根據具有指定的 MemoryStream 屬性設定之位元組陣列,來初始化 CanWrite 類別之新的不可調整大小的執行個體。Initializes a new non-resizable instance of the MemoryStream class based on the specified byte array with the CanWrite property set as specified.

MemoryStream(Byte[], Int32, Int32)

根據位元組陣列的指定區域 (索引),來初始化 MemoryStream 類別之新的不可調整大小的執行個體。Initializes a new non-resizable instance of the MemoryStream class based on the specified region (index) of a byte array.

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

根據位元組陣列的指定區域 (且該區域使用依指定所設定的 MemoryStream 屬性),來初始化 CanWrite 類別之新的不可調整大小的執行個體。Initializes a new non-resizable instance of the MemoryStream class based on the specified region of a byte array, with the CanWrite property set as specified.

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

根據指定的位元組陣列區域 (且該區域使用依指定所設定的 MemoryStream 屬性和依指定所設定的呼叫 CanWrite 的能力),來初始化 GetBuffer() 類別的新執行個體。Initializes a new instance of the MemoryStream class based on the specified region of a byte array, with the CanWrite property set as specified, and the ability to call GetBuffer() set as specified.

MemoryStream()

使用初始化為零的可擴展容量,初始化 MemoryStream 類別的新執行個體。Initializes a new instance of the MemoryStream class with an expandable capacity initialized to zero.

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

備註

、和屬性都設定為trueCanWrite CanSeek CanReadThe CanRead, CanSeek, and CanWrite properties are all set to true.

當您使用SetLength方法將長度設定為大於目前資料流程容量的值時,目前資料流程的容量會自動增加。The capacity of the current stream automatically increases when you use the SetLength method to set the length to a value larger than the capacity of the current stream.

此函式會公開會傳回的GetBuffer基礎資料流程。This constructor exposes the underlying stream, which GetBuffer returns.

另請參閱

MemoryStream(Byte[])

根據指定的位元組陣列,初始化 MemoryStream 類別之不可調整大小的執行個體。Initializes a new non-resizable instance of the MemoryStream class based on the specified byte array.

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[]

用於建立目前資料流之不帶正負號位元組的陣列。The array of unsigned bytes from which to create the current stream.

例外狀況

buffernullbuffer is null.

備註

、和屬性都設定為trueCanWrite CanSeek CanReadThe CanRead, CanSeek, and CanWrite properties are all set to true. Capacity設定為所指定位元組陣列的長度。Capacity is set to the length of the specified byte array. 新的資料流程可以寫入,但是無法調整大小。The new stream can be written to, but is not resizable.

資料流程的長度不能設定為大於指定位元組陣列之初始長度的值;不過,可以截斷資料流程(請參閱SetLength)。The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see SetLength).

這個構造函式不會公開基礎資料流程。This constructor does not expose the underlying stream. GetBufferUnauthorizedAccessException回。GetBuffer throws UnauthorizedAccessException.

另請參閱

MemoryStream(Int32)

使用初始化為指定的可擴展容量,初始化 MemoryStream 類別的新執行個體。Initializes a new instance of the MemoryStream class with an expandable capacity initialized as specified.

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

參數

capacity
Int32

內部陣列的初始大小,以位元組為單位。The initial size of the internal array in bytes.

例外狀況

capacity 為負。capacity is negative.

範例

這個程式碼範例是針對MemoryStream類別提供之較大範例的一部分。This code example is part of a larger example provided for the MemoryStream class.

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

備註

、和屬性都設定為trueCanWrite CanSeek CanReadThe CanRead, CanSeek, and CanWrite properties are all set to true.

當您使用SetLength方法將長度設定為大於目前資料流程容量的值時,容量會自動增加。The capacity automatically increases when you use the SetLength method to set the length to a value larger than the capacity of the current stream. 除了以 byte MemoryStream [] 參數所建立的之外,在MemoryStream展開的MemoryStream結尾處寫入作業。Except for a MemoryStream constructed with a byte[] parameter, write operations at the end of a MemoryStream expand the MemoryStream.

此函式會GetBuffer公開傳回的基礎資料流程。This constructor exposes the underlying stream that GetBuffer returns.

另請參閱

MemoryStream(Byte[], Boolean)

根據具有指定的 MemoryStream 屬性設定之位元組陣列,來初始化 CanWrite 類別之新的不可調整大小的執行個體。Initializes a new non-resizable instance of the MemoryStream class based on the specified byte array with the CanWrite property set as specified.

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[]

用於建立這個資料流之不帶正負號位元組的陣列。The array of unsigned bytes from which to create this stream.

writable
Boolean

CanWrite 屬性的設定值,判斷資料流是否支援寫入。The setting of the CanWrite property, which determines whether the stream supports writing.

例外狀況

buffernullbuffer is null.

備註

和屬性都設定為trueCanRead CanSeekThe CanRead and CanSeek properties are both set to true. Capacity設定為所指定位元組陣列的長度。Capacity is set to the length of the specified byte array.

資料流程的長度不能設定為大於指定位元組陣列之初始長度的值;不過,可以截斷資料流程(請參閱SetLength)。The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see SetLength).

這個構造函式不會公開基礎資料流程。This constructor does not expose the underlying stream. GetBufferUnauthorizedAccessException回。GetBuffer throws UnauthorizedAccessException.

另請參閱

MemoryStream(Byte[], Int32, Int32)

根據位元組陣列的指定區域 (索引),來初始化 MemoryStream 類別之新的不可調整大小的執行個體。Initializes a new non-resizable instance of the MemoryStream class based on the specified region (index) of a byte array.

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[]

用於建立這個資料流之不帶正負號位元組的陣列。The array of unsigned bytes from which to create this stream.

index
Int32

buffer 中資料流開始處的索引。The index into buffer at which the stream begins.

count
Int32

資料流的長度,以位元組為單位。The length of the stream in bytes.

例外狀況

buffernullbuffer is null.

indexcount 小於零。index or count is less than zero.

緩衝區長度減去 index 會小於 countThe buffer length minus index is less than count.

備註

、和屬性全都設定為true,但無法變更容量。 CanWrite CanSeek CanReadThe CanRead, CanSeek, and CanWrite properties are all set to true, but the capacity cannot be changed. Capacity 設定為 countCapacity is set to count.

資料流程的長度不能設定為大於指定位元組陣列之初始長度的值;不過,可以截斷資料流程(請參閱SetLength)。The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see SetLength).

這個構造函式不會公開基礎資料流程。This constructor does not expose the underlying stream. GetBufferUnauthorizedAccessException回。GetBuffer throws UnauthorizedAccessException. 不過,您可以寫入資料流程。However, you can write to the stream.

另請參閱

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

根據位元組陣列的指定區域 (且該區域使用依指定所設定的 MemoryStream 屬性),來初始化 CanWrite 類別之新的不可調整大小的執行個體。Initializes a new non-resizable instance of the MemoryStream class based on the specified region of a byte array, with the CanWrite property set as specified.

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[]

用於建立這個資料流之不帶正負號位元組的陣列。The array of unsigned bytes from which to create this stream.

index
Int32

buffer 中資料流開始處的索引。The index in buffer at which the stream begins.

count
Int32

資料流的長度,以位元組為單位。The length of the stream in bytes.

writable
Boolean

CanWrite 屬性的設定值,判斷資料流是否支援寫入。The setting of the CanWrite property, which determines whether the stream supports writing.

例外狀況

buffernullbuffer is null.

indexcount 為負值。index or count are negative.

緩衝區長度減去 index 會小於 countThe buffer length minus index is less than count.

備註

和屬性都設定為trueCanRead CanSeekThe CanRead and CanSeek properties are both set to true. Capacity 設定為 countCapacity is set to count.

資料流程的長度不能設定為大於指定位元組陣列之初始長度的值;不過,可以截斷資料流程(請參閱SetLength)。The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see SetLength).

這個構造函式不會公開基礎資料流程。This constructor does not expose the underlying stream. GetBufferUnauthorizedAccessException回。GetBuffer throws UnauthorizedAccessException. 不過,如果writabletrue,您可以寫入資料流程。However, you can write to the stream if writable is true.

另請參閱

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

根據指定的位元組陣列區域 (且該區域使用依指定所設定的 MemoryStream 屬性和依指定所設定的呼叫 CanWrite 的能力),來初始化 GetBuffer() 類別的新執行個體。Initializes a new instance of the MemoryStream class based on the specified region of a byte array, with the CanWrite property set as specified, and the ability to call GetBuffer() set as specified.

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[]

用於建立這個資料流之不帶正負號位元組的陣列。The array of unsigned bytes from which to create this stream.

index
Int32

buffer 中資料流開始處的索引。The index into buffer at which the stream begins.

count
Int32

資料流的長度,以位元組為單位。The length of the stream in bytes.

writable
Boolean

CanWrite 屬性的設定值,判斷資料流是否支援寫入。The setting of the CanWrite property, which determines whether the stream supports writing.

publiclyVisible
Boolean

啟用 GetBuffer() (傳回從其中建立資料流的不帶正負號的位元組陣列),則為 true,否則為 falsetrue to enable GetBuffer(), which returns the unsigned byte array from which the stream was created; otherwise, false.

例外狀況

buffernullbuffer is null.

indexcount 為負。index or count is negative.

緩衝區長度減去 index 會小於 countThe buffer length minus index is less than count.

備註

和屬性都設定為trueCanRead CanSeekThe CanRead and CanSeek properties are both set to true. Capacity 設定為 countCapacity is set to count.

可以將新的資料流程實例寫入,但是無法變更Capacity基礎位元組陣列的。The new stream instance can be written to, but the Capacity of the underlying byte array cannot be changed. 資料流程的長度不能設定為大於指定位元組陣列之初始長度的值;不過,可以截斷資料流程(請參閱SetLength)。The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see SetLength).

另請參閱

適用於