Alex Rivera | Logout

When should I use the using Statement?

Asked 2012-04-07T18:51:06.943
12

Possible Duplicate:
What is the C# Using block and why should I use it?

I'm converting an old site to C# and I'm not sure when I should be using 'using'. Are there any general guidelines? I know of the benefits, but I'm not 100% sure how to use it. Is it every time I 'new' a method/property?

SqlConnection awesomeConn = new SqlConnection(connection);
Edit
Report

1 Answer

0

Using is a convenience that allows you to assure that you can't exit a block with out disposing of the resource. It can and should be utilized whenever you have to utilize an IDisposable implementer in a local code block.

answered 2012-04-07T18:54:13.010

Your Answer