Are there any side effects of returning from inside a using() statement?

前端 未结 5 1390
一向
一向 2021-01-31 07:02

Returning a method value from inside a using statement that gets a DataContext seems to always work fine, like this:

public sta         


        
5条回答
  •  滥情空心
    2021-01-31 07:18

    Have a look at this

    Understanding the 'using' statement in C#

    The CLR converts your code into MSIL. And the using statement gets translated into a try and finally block. This is how the using statement is represented in IL. A using statement is translated into three parts: acquisition, usage, and disposal. The resource is first acquired, then the usage is enclosed in a try statement with a finally clause. The object then gets disposed in the finally clause.

提交回复
热议问题