Disposable Using Pattern

前端 未结 5 1342
天涯浪人
天涯浪人 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:27

    The using statement only knows about Dispose(), but Stream.Dispose calls Close(), as documented in MSDN:

    Note that because of backward compatibility requirements, this method's implementation differs from the recommended guidance for the Dispose pattern. This method calls Close, which then calls Stream.Dispose(Boolean).

提交回复
热议问题