Tuesday, June 30, 2009

Using Keyword in C#

When you use the using statement the Compiler automatically throws try and finally block.inside the Finally block compiler automatically cast to IDisposable inrerface and automatically calls dispose method.

Note : using can be used only which it supports IDisposable interface.So it reduce the syntax and help to dispose method automatically.reduce the number of errors.

E,g

Using(SqlConnection con = new SqlConnection())

{

…………….

}

The compailer automatically added try - finally to ‘con’ . and do the previous operation by using IDisposable.

0 comments:

 
Counter