问题描述
HttpWebReponse
工具的IDisposable
界面,但为什么没有处置
方法。它仅包含关闭
方法。将使用
仍然可用于此类模式?
HttpWebReponse
implements IDisposable
interface, but why is there no Dispose
method. It only contains Close
method. Will be using
pattern still available for this class?
推荐答案
HttpWebResponse IDisposable的实现明确的接口。所以,你可以叫处置
只有当你施放HttpWebResponse到的IDisposable
。的HttpWebResponse内部调用处置关闭
方法。
HttpWebResponse implements IDisposable interface explicitly. So you can call Dispose
only when you cast HttpWebResponse to IDisposable
. The Close
method of HttpWebResponse calls Dispose internally.
HttpWebResponse response = // assigned from somewhere
IDisposable disposableResponse = response as IDisposable;
disposableResponse.Dispose();
由于 HttpWebResponse
工具的IDisposable
您可以使用它与一个使用语句。
Since HttpWebResponse
implements IDisposable
you can use it with an using-statement.
HttpWebResponse response = // assigned from somewhere
using(response) {
// do your work;
}
这篇关于为什么会出现在HttpWebResponse没有Dispose方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!