问题
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?
回答1:
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();
Since HttpWebResponse implements IDisposable you can use it with an using-statement.
HttpWebResponse response = // assigned from somewhere
using(response) {
// do your work;
}
来源:https://stackoverflow.com/questions/8063504/why-is-there-no-dispose-method-on-httpwebresponse