Trying to understand the 'using' statement better

后端 未结 8 1250
小鲜肉
小鲜肉 2021-01-18 17:26

I have read a couple of articles about the using statement to try and understand when it should be used. It sound like most people reckon it should be used as much as possib

8条回答
  •  佛祖请我去吃肉
    2021-01-18 17:35

    IMHO, what you need to ask yourself is: What are the alternatives? Try/finally blocks? Are they more readable? More maintainable? In almost all cases, the answer is going to be "no".

    So use using. It's the closest thing C# has to C++'s RAII pattern and it's all good :-)

提交回复
热议问题