Sunday, June 29, 2008

c# using statement

The C# 'using' statement provides a convenient syntax that ensures the correct use of IDisposable objects.

Example:


using (BlackJackForm blackjackform = new BlackJackForm())
{
Hide();
blackjackform.ShowDialog();
Show();
}


The above is the equivalent of the following more verbose code:


BlackJackForm blackjackform = new BlackJackForm()
try {
Hide();
blackjackform.ShowDialog();
Show();
}
finally {
blackjackform.Dispose();
}


The using statement only works with items implementing the IDisposable interface.

1 comment:

jowdjbrown said...

The C# 'using' statement provides a convenient syntax that ensures the correct use of IDisposable objects.install mac on PC