Posted by: Cirilo Meggiolaro | 10/28/2008

Tip of the day #14 – Calling Dispose method automatically with “using” statement

Do you know there is an easy way to call automatically the Dispose method of objects that implement the IDisposable interface?

The using statement provides a small block of code that you can use to declare, instantiate and define the scope of your object as well.

The using statement will invoke the dispose method of your object as soon as it goes out of scope.

How to…

using (DataSet ds = new DataSet())
{
/// Your code goes here
}

/// The Dispose method from the DataSet will be called

 
To get full details about the using statement, click here!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: