return the variable used for using inside the using C#

Posted by di3go on Stack Overflow See other posts from Stack Overflow or by di3go
Published on 2010-05-12T20:53:07Z Indexed on 2010/05/12 20:54 UTC
Read the original article Hit count: 265

Hello,

I am returning the variable I am creating in a using statement inside the using statement (sounds funny):

public DataTable foo ()
{
    using (DataTable properties = new DataTable())
    {
       // do something
       return properties;
    }
}

Will this Dispose the properties variable??

After doing this am still getting this Warning:

Warning 34 CA2000 : Microsoft.Reliability : In method 'test.test', call System.IDisposable.Dispose on object 'properties' before all references to it are out of scope.

Any Ideas?

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about dispose