Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning from inside the scope of a 'using' statement?

Tags:

c#

.net

I've got some code that looks like this:

using (DBDataContext dc = new DBDataContext(ConnectionString))
{
    Main main = new Main
    {
        ClientTime = clientTime
    };
    dc.Mains.InsertOnSubmit(main);
    dc.SubmitChanges();
    return main.ID;
}

If I return from inside a "using", will the using still clean up?

like image 416
Guy Avatar asked Jan 02 '09 23:01

Guy


1 Answers

Yes, and that's one of the big advantages of using it.

like image 138
Otávio Décio Avatar answered Oct 03 '22 16:10

Otávio Décio