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.

適用於

另請參閱