Does .Disposing a StreamWriter close the underlying stream?

前端 未结 6 2026
星月不相逢
星月不相逢 2020-12-01 18:02

The StreamWriter.Close() says it also closes the underlying stream of the StreamWriter. What about StreamWriter.Dispose ? Does Dispose also dispose and/or close the underlyi

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 18:28

    To quote from Framework Design Guidelines by Cwalina and Abrams in the section about the dispose pattern:

    CONSIDER providing method Close(), in addition to the Dispose(), if close is standard terminology in the area.

    Apparently Microsoft follow their own guidelines, and assuming this is almost always a safe bet for the .NET base class library.

提交回复
热议问题