What are the situations we can use "USING" keyword in C#

Posted by Sivakumar.S under C# on 6/5/2012 | Points: 10 | Views : 1153 | Status : [Member] | Replies : 5
Hi all,

What are the situations we can use "USING" keyword in C#. As per my knowledge we are using to import namespace. Is any other usage for "USING" keyword in C# ?. And also please clear what are the situations we should use "IS" AND "AS" keyword in C#. can anyone explain with detail explanation and its usage?

siva


Responses

Posted by: Kavi.Sirius on: 6/5/2012 [Member] Starter | Points: 25

Up
0
Down
hi

Refer this link

http://www.mindfiresolutions.com/Two-ways-to-use-using-keyword-in-C-1160.php

Regards
Kavi.n

Sivakumar.S, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/5/2012 [Member] Starter | Points: 25

Up
0
Down
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/

Ajay
ajaypatelfromsanthal.blogspot.in

Sivakumar.S, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sivakumar.S on: 6/5/2012 [Member] Starter | Points: 25

Up
0
Down
Hi all,

Thanks for your explanations.




siva

Sivakumar.S, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 6/7/2012 [Member] Starter | Points: 25

Up
0
Down
"Using" keyword takes the parameter of type IDisposable.

After using it dispose the connection by default 25 connection are allowed in Dot.net

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Sivakumar.S, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 6/11/2012 [Member] Bronze | Points: 25

Login to post response