MemoryStream 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 MemoryStream 类的新实例。
重载
| 名称 | 说明 |
|---|---|
| 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() 集。 |
MemoryStream()
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
使用可扩展容量初始化为零的类的新实例 MemoryStream 。
public:
MemoryStream();
public MemoryStream();
Public Sub New ()
注解
CanRead属性CanSeek和CanWrite属性都设置为 true。
使用 SetLength 方法将长度设置为大于当前流的容量的值时,当前流的容量会自动增加。
此构造函数公开返回的基础流 GetBuffer 。
另请参阅
适用于
MemoryStream(Byte[])
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- 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[]
要从中创建当前流的无符号字节数组。
例外
buffer 是 null。
注解
CanRead属性CanSeek和CanWrite属性都设置为 true。
Capacity 设置为指定字节数组的长度。 新流可以写入,但不能调整大小。
流的长度不能设置为大于指定字节数组的初始长度的值;但是,可以截断流(请参阅 SetLength)。
此构造函数不公开基础流。 GetBuffer throws UnauthorizedAccessException.
另请参阅
适用于
MemoryStream(Int32)
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- 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
内部数组的初始大小(以字节为单位)。
例外
示例
该代码示例是 MemoryStream 类中的一个较大示例的一部分。
using(MemoryStream memStream = new MemoryStream(100))
Dim memStream As New MemoryStream(100)
注解
CanRead属性CanSeek和CanWrite属性都设置为 true。
使用 SetLength 该方法将长度设置为大于当前流的容量的值时,容量会自动增加。 除使用 byte[] 参数构造的MemoryStream构造外,在展开的MemoryStream末尾MemoryStream写入操作。
此构造函数公开返回的基础流 GetBuffer 。
另请参阅
适用于
MemoryStream(Byte[], Boolean)
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- 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[]
要从中创建此流的无符号字节数组。
例外
buffer 是 null。
注解
和CanReadCanSeek属性都设置为 true。
Capacity 设置为指定字节数组的长度。
流的长度不能设置为大于指定字节数组的初始长度的值;但是,可以截断流(请参阅 SetLength)。
此构造函数不公开基础流。 GetBuffer throws UnauthorizedAccessException.
另请参阅
适用于
MemoryStream(Byte[], Int32, Int32)
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- 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
流的长度(以字节为单位)。
例外
buffer 是 null。
index 或 count 小于零。
缓冲区长度减号 index 小于 count。
注解
属性CanReadCanSeek和CanWrite属性都设置为true,但容量无法更改。 将 Capacity 设置为 count。
流的长度不能设置为大于指定字节数组的初始长度的值;但是,可以截断流(请参阅 SetLength)。
此构造函数不公开基础流。 GetBuffer throws UnauthorizedAccessException. 但是,可以写入流。
另请参阅
适用于
MemoryStream(Byte[], Int32, Int32, Boolean)
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- 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
流的长度(以字节为单位)。
例外
buffer 是 null。
index 或 count 为负数。
缓冲区长度减号 index 小于 count。
注解
和CanReadCanSeek属性都设置为 true。 将 Capacity 设置为 count。
流的长度不能设置为大于指定字节数组的初始长度的值;但是,可以截断流(请参阅 SetLength)。
此构造函数不公开基础流。
GetBuffer throws UnauthorizedAccessException. 但是,如果为 writable,则可以写入流true。
另请参阅
适用于
MemoryStream(Byte[], Int32, Int32, Boolean, Boolean)
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- MemoryStream.cs
- Source:
- 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
流的长度(以字节为单位)。
- publiclyVisible
- Boolean
例外
buffer 是 null。
index 或 count 为负数。
缓冲区长度减号 index 小于 count。
注解
和CanReadCanSeek属性都设置为 true。 将 Capacity 设置为 count。
可以写入新流实例,但 Capacity 基础字节数组无法更改。 流的长度不能设置为大于指定字节数组的初始长度的值;但是,可以截断流(请参阅 SetLength)。