MemoryStream.ToArray 方法

定义

将流内容写入字节数组,而与 Position 属性无关。Writes the stream contents to a byte array, regardless of the Position property.

public:
 virtual cli::array <System::Byte> ^ ToArray();
public virtual byte[] ToArray ();
abstract member ToArray : unit -> byte[]
override this.ToArray : unit -> byte[]
Public Overridable Function ToArray () As Byte()

返回

Byte[]

新的字节数组。A new byte array.

注解

此方法省略数组 MemoryStream 中未使用的字节。This method omits unused bytes in MemoryStream from the array. 若要获取整个缓冲区,请使用 GetBuffer 方法。To get the entire buffer, use the GetBuffer method.

此方法以字节数组的形式返回 MemoryStream 内容的副本。This method returns a copy of the contents of the MemoryStream as a byte array. 如果当前实例是在提供的字节数组上构造的,则返回此实例具有访问权限的数组部分的副本。If the current instance was constructed on a provided byte array, a copy of the section of the array to which this instance has access is returned. 有关详细信息,请参阅 MemoryStream 构造函数。See the MemoryStream constructor for details.

备注

此方法在 MemoryStream 关闭时有效。This method works when the MemoryStream is closed.

适用于

另请参阅