StreamReader.Dispose(Boolean) StreamReader.Dispose(Boolean) StreamReader.Dispose(Boolean) StreamReader.Dispose(Boolean) Method


關閉基礎資料流,接著釋放 StreamReader 所使用的 Unmanaged 資源,然後再選擇性釋放 Managed 資源。Closes the underlying stream, releases the unmanaged resources used by the StreamReader, and optionally releases the managed resources.

 override void Dispose(bool disposing);
protected override void Dispose (bool disposing);
override this.Dispose : bool -> unit
Protected Overrides Sub Dispose (disposing As Boolean)


Boolean Boolean Boolean Boolean

true 表示會同時釋放 Managed 和 Unmanaged 資源,false 則表示只釋放 Unmanaged 資源。true to release both managed and unmanaged resources; false to release only unmanaged resources.


這個方法會呼叫公用Dispose方法和Finalize方法。This method is called by the public Dispose method and the Finalize method. Dispose 叫用受保護Dispose方法使用disposing參數設為 true。Dispose invokes the protected Dispose method with the disposing parameter set to true. Finalize 叫用Disposedisposing設為 false。Finalize invokes Dispose with disposing set to false.

disposing參數是true,這個方法會釋放所有資源都保留的任何 managed 物件StreamReader物件參考。When the disposing parameter is true, this method releases all resources held by any managed objects that the StreamReader object references. 這個方法會叫用每個參考物件的 Dispose 方法。This method invokes the Dispose method of each referenced object.



可以多次呼叫 dispose 的其他物件。Dispose can be called multiple times by other objects. 覆寫時Dispose(Boolean),請小心不要參考先前處置好的呼叫 Dispose [cref,...] 中的物件。如需有關如何實作Dispose(Boolean)請參閱 <<c2> 實作 Dispose 方法When overriding Dispose(Boolean), be careful not to reference objects that have been previously disposed of in an earlier call to Dispose[cref,...]. For more information about how to implement Dispose(Boolean) see Implementing a Dispose Method.

如需詳細資訊Dispose()Finalize(),請參閱清除 Unmanaged 資源總For more information about Dispose() and Finalize(), see Cleaning Up Unmanaged Resources.