What is the difference between the using statement and directive in C#?

前端 未结 5 2034
深忆病人
深忆病人 2020-12-18 05:11

this is basically a tutorial question to ask since am a beginner I would like to what is a difference between the using statement we use at start of our C# code to include a

5条回答
  •  死守一世寂寞
    2020-12-18 05:43

    using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))

    This using disposes the adapter object automatically once the control leaves the using block.

    This is equivalent to the call

    SqlDataAdapter adapter = new SqlDataAdapter(cmd)
    adapter.dispose();
    

    See official documentation on this: http://msdn.microsoft.com/en-us/library/yh598w02(v=vs.71).aspx

提交回复
热议问题