Hi Guys
Please tell me the
"using" Keyword in C#
thanks
The "using" Keyword in C#
Ask by Anonymous User
Updated 09 Feb 2013
hi 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