Here is Sample Code for Understanding Use of " Using "
using(SqlConnection con= new SqlConnection(connectionString) )
{
SqlCommand cmd = new SqlCommand(commandString, sqlconnection);
con.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
//DO
}
}
}
"Using" keyword takes the parameter of type IDisposable.
Whenever you are using any IDisposable type object you should use the "using" keyword to handle automatically when it should close or dispose.
Internally using keyword calls the Dispose() method to dispose the IDisposable object.
Object is disposed automatically on the end of this statement.
For is and as operator
it is use for check casting and return Boolean value.
check for more details
http://ekrishnakumar.wordpress.com/2006/07/08/c-is-and-as-operators/ http://ajaypatelfromsanthal.blogspot.in
Sivakumar.S, if this helps please login to Mark As Answer. |
Reply | Alert Moderator