Can an object be declared above a using statement instead of in the brackets

后端 未结 5 1571
执念已碎
执念已碎 2021-01-17 08:23

Most of the examples of the using statement in C# declare the object inside the brackets like this:

using (SqlCommand cmd = new SqlCommand(\"SELECT * FROM Cu         


        
5条回答
  •  心在旅途
    2021-01-17 09:02

    The idea behind using is to define a scope, outside of which an object or objects will be disposed.

    If you declare the object you are about to use inside using in advance, there's no point to use the using statement at all.

提交回复
热议问题