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.
Remember Me
a@href@title, strike
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Michal Talaga
E-mail