Stream.SetLength(Int64) Stream.SetLength(Int64) Stream.SetLength(Int64) Stream.SetLength(Int64) Method

定義

在衍生類別中覆寫時,設定目前資料流的長度。When overridden in a derived class, sets the length of the current stream.

public:
 abstract void SetLength(long value);
public abstract void SetLength (long value);
abstract member SetLength : int64 -> unit
Public MustOverride Sub SetLength (value As Long)

參數

value
Int64 Int64 Int64 Int64

想要的目前資料流長度 (單位為位元組)。The desired length of the current stream in bytes.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

資料流不支援寫入和搜尋,例如,如果資料流是從管道或主控台 (Console) 輸出所建構。The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output.

關閉資料流後呼叫了方法。Methods were called after the stream was closed.

備註

如果指定的值小於目前資料流的長度,則會截斷資料流。If the specified value is less than the current length of the stream, the stream is truncated. 如果指定的值大於目前的資料流的長度,則會展開資料流。If the specified 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 length are not defined.

資料流必須支援寫入和搜尋的SetLength運作。A stream must support both writing and seeking for SetLength to work.

使用CanWrite屬性來判斷目前的執行個體是否支援寫入,而CanSeek屬性來判斷是否支援搜尋。Use the CanWrite property to determine whether the current instance supports writing, and the CanSeek property to determine whether seeking is supported.

適用於

另請參閱