Disposable Using Pattern

前端 未结 5 1309
天涯浪人
天涯浪人 2021-01-04 04:56
  using (FileStream fileStream = new FileStream(path))
  {
    // do something
  }

Now I know the using pattern is an implementation of IDisposable

5条回答
  •  感情败类
    2021-01-04 05:36

    Close() is not part of the IDisposable interface so using has no way to know whether it should be called or not. using will only call Dispose(), but intelligently designed objects will close themselves in the Dispose() method.

提交回复
热议问题