By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,679 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,679 IT Pros & Developers. It's quick & easy.

C#/.Net - Doubt how"Using" Statement is implimented

P: 29
Hi all,

I have a doubt regarding the "Using" statement

if i write a code like this....

using (sqlDataReader)

do something ....


do I need to explicitly close the DataReader object or

will it be taken care off as i'm using the "Using" statement, will it close & dispose ?

I would like to know whats the best practice ?
Apr 1 '08 #1
Share this Question
Share on Google+
2 Replies

Shashi Sadasivan
Expert 100+
P: 1,435
that would be an appropriate syntax.
Anything inside a using statement should implement the IDisposable interface.
so that at the end of the using clause, the object is disposed.

However with your syntax you can still run into problems as you can still access the sqlDataReader as it will be disposed after the using clause.

The method would be to declare the datareader inside the using statement

using Statement (C#)
Apr 1 '08 #2

P: 29
Thanks ..... i understood what u said.
Apr 1 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.