UnmanagedMemoryStream.SetLength(Int64) UnmanagedMemoryStream.SetLength(Int64) UnmanagedMemoryStream.SetLength(Int64) UnmanagedMemoryStream.SetLength(Int64) Method


將資料流長度設為指定值。Sets the length of a stream to a specified value.

 override void SetLength(long value);
public override void SetLength (long value);
override this.SetLength : int64 -> unit
Public Overrides Sub SetLength (value As Long)


Int64 Int64 Int64 Int64

資料流的長度。The length of the stream.


發生 I/O 錯誤。An I/O error has occurred.

基礎記憶體不支援寫入。The underlying memory does not support writing.

-或--or- 嘗試進行資料流寫入,且 CanWrite 屬性為 falseAn attempt is made to write to the stream and the CanWrite property is false.

指定的 value 超過資料流容量。The specified value exceeds the capacity of the stream.

-或--or- 指定的 value 為負數。The specified value is negative.


如果指定的值小於目前的資料流程長度, 則會截斷資料流程。If the given value is less than the current length of the stream, the stream is truncated. 如果指定的值大於資料流程的目前長度, 則會展開資料流程。If the given value is larger than the current length of the stream, the stream is expanded. 如果資料流程已展開, 則不會定義舊的和新長度之間的資料流程內容。If the stream is expanded, the contents of the stream between the old and the new lengths are undefined.

資料流程必須同時支援寫入和搜尋SetLength , 才能正常工作。A stream must support both writing and seeking for SetLength to work.