Why does HttpListener explicitly implement IDisposable. This means you have to cast to IDisposable before calling d开发者_如何学Pythonispose and in my opinion makes the fact you have to call dispose less obvious.
You don't need an explicit cast if you use a
usingblock. (This is the preferred idiom, where possible, for dealing withIDisposableobjects.)using (HttpListener hl = /* ... */) { // ... }It has a
Closemethod which is pretty-much an alias forDispose. (Not my favourite pattern, but the framework designers seem to like it!)HttpListener hl = /* ... */ try { // ... } finally { hl.Close(); }
加载中,请稍侯......
精彩评论