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 assembly and namespaces
like this:
using System.Web.Services;
and when we write inside the code within the method or code.
like this:
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
is there any difference or they both are same, any guidance would be helpful and appreciated.
The first (Using Directive) is to bring a namespace into scope.
This is for example, so you can write
rather than
The second (Using Statement) one is for correctly using (creating and disposing) an object implementing the IDisposable interface.
For example:
Here, the
Fonttype implementsIDisposablebecause it uses unmanaged resources that need to be correctly disposed of when we are no-longer using theFontinstance (font1).