Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the using statement with WinForms... Good Practice?

I understand the concept and reasons behind using the using statement, and I use it with things like file resources and remote connections, I was wondering if it is good practice to use the using statement with WinForm forms and dialogs?

using (MyDialog dlg = new MyDialog())
{
    if (dlg.ShowDialog() == EDialogResult.OK)
    {
        // Do Something
    }
}

Thanks!

like image 699
Nate Heinrich Avatar asked Mar 08 '10 23:03

Nate Heinrich


1 Answers

With Dialogs only. But then it is a very good practice.

You will find that it doesn't work around Show(), because using(){} can only be used inside 1 method and you never want to Close again right after a Show().

like image 190
Henk Holterman Avatar answered Oct 20 '22 07:10

Henk Holterman