C# using statement catch error

后端 未结 16 1310
轻奢々
轻奢々 2021-01-30 14:06

I am just looking at the using statement, I have always known what it does but until now not tried using it, I have come up with the below code:

 using (SqlComma         


        
16条回答
  •  温柔的废话
    2021-01-30 14:37

    There may be no advantage to using a using statement in this case if you're going to have a try/catch/finally block anyway. As you know, the using statement is syntactic sugar for a try/finally that disposes of the IDisposable object. If you're going to have your own try/finally anyway, you can certainly do the Dispose yourself.

    This really mainly boils down to style - your team may be more comfortable with using statements or using statements may make the code look cleaner.

    But, if the boilerplate the using statement would be hiding is there anyway, go ahead and handle things yourself if that's your preference.

提交回复
热议问题