Using the Using Statement

by Nick 9. November 2006 12:55

Rory shows us a couple of examples of how to use the C# using statement.  Thankfully VB 2005 also includes this statement so that VB.NET coders can write:

Using ts As New Data.SqlClient.SqlConnection, _
          ts2 As New Data.SqlClient.SqlConnection
      'Do stuff...
End Using

What I would like to see is a compiler that is intilligent enough so that if I declare an IDisposable object on the stack (ie as a method variable) it will automatically call dispose when the method exits.  This would mostly negate the need for the using statement.  Oh, wait doesn't the Managed C++/CLI compiler do this....

Tags:

Powered by BlogEngine.NET 2.0.0.36

Automotive Theme by Car Leasing Experts

 

Page List