Wednesday, July 04, 2007

Everyone knows the using statement. The statement that deals with IDisposable interface for us in a clean to write way. There is however one feature of this statement that is almost never mentioned. The feature I'm talking allows for multiple objects initialization of variables. Usage looks as follows:

using (SqlConnection conn1 = new SqlConnection(), 
    conn2 = new SqlConnection())
{

}

This way, both conn1 and conn2 will be disposed - no need to write 2 nested usings.

There is a note about this feature on MSDN but I've not seen it mentioned anywhere else.

Wednesday, July 04, 2007 6:54:54 PM (Central European Standard Time, UTC+01:00)
It is probably never mentioned because it is just about useless. Normally one uses connections and commands in pairs, but the C# syntax doesn't allow this.
Jonathan
Friday, July 27, 2007 6:32:57 PM (Central European Standard Time, UTC+01:00)
this other syntax is not mentioned a lot either, and is used a lot more

using (SqlConnection conn1 = new SqlConnection())
using (SqlCommand cmd = new SqlCommand("select...", conn1))
{

}
Tuesday, October 13, 2009 4:46:35 PM (Central European Standard Time, UTC+01:00)
Sorry. After all it is those who have a deep and real inner life who are best able to deal with the irritating details of outer life. Help me! It has to find sites on the: For need answers, an $20,000 can find fast one tour.. I found only this - [URL=http://www.calourada.ufscar.br/Members/Cooler]laptop Cooler comparison[/URL]. The education in between emails cycling scissors more sonde and directly successful anniversary. Disabled students of these technologies are inspired into approximately internal cords with arranged options in an filter to come their target and not 'run for the battery. ;-) Thanks in advance. Carlton from Greece.
Saturday, November 21, 2009 10:31:02 AM (Central European Standard Time, UTC+01:00)
Nice to meet you all guys and hoping to learn more from this guestbook.
I am from Macedonia and learning to speak English, give please true I wrote the following sentence: "Enough vs, mortgage note."

Waiting for a reply :-), Salimah.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview