When are C# “using” statements most useful?

后端 未结 14 1947
没有蜡笔的小新
没有蜡笔的小新 2021-02-13 05:33

So a using statement automatically calls the dispose method on the object that is being \"used\", when the using block is exited, right?

But when is this necessary/benef

14条回答
  •  渐次进展
    2021-02-13 06:10

    I asked a very similar question here:

    Resources that have to be manually cleaned up in C#?

    And i got a nice piece of advice in the form of:

    In general, if something has a Dispose method, you should call it when you've finished with it, or, if you can, wrap it up in a using statement.

提交回复
热议问题