Are you a Using user?
Over at Angry Coder, the talk about the "Using" block. This is something coders should use if possible since it helps do object cleanup for items like GDI+ (Graphics) and connections (streams, files, ...). It helps define when the object leaves scope and helps close streams, clear up memory, reset defaults, ... when you're done with that object automatically! You can make your own objects able to use the Using block just by implementing the IDispose interface by adding in the Dispose() method. It helps clean up so you don't have to.
Here is a quick example of a using block with a SqlConnection object. If you ever wondered what gets called in that Dispose method but don't have access to the source, use Reflector to verify.
C#
using (SqlConnection cn = new SqlConnection(sConnString)) { ... }VB.Net
Using cn As New SqlConnection(sConnString)
...
End Using
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using