Hi Guys
Please tell me the
"using" Keyword in C#
thanks
The "using" Keyword in C#
3789
17-Nov-2012
Shankar M
09-Feb-2013AVADHESH PATEL
19-Nov-2012hi Pravesh
The reason for the "using" statement is to ensure that the object is always disposed correctly, and it doesn't require explicit code to ensure that this happens.
{ // limits scope of myResMyResource myRes= new MyResource();
try
{
myRes.DoSomething();
}
finally
{
// Check for a null resource.
if (myRes!= null)
// Call the object's Dispose method.
((IDisposable)myRes).Dispose();
}
}
We can write above code like this