I have declared datatable inside using block which calls the Dispose method at the end of the scope.
using (DataTable dt = Admin_User_Functions.Admin_KitItems_GetItems())
{
...
}
But in reflector, datatable doesnt seens to have Dispose function

How is that ?
System.Data.DataTable extends System.ComponentModel.MarshalByValueComponent and, MarshalByValueComponent implements IDisposable.
Reflector would not display the methods of the base type unless they are overriden in the derived type.
DataTable inherited from MarshalByValueComponent class which implements IDisposable interface (see below), C# allows calling base class public methods for the instances of derived classes.
public class DataTable : MarshalByValueComponent,
IListSource, ISupportInitializeNotification,
ISupportInitialize, ISerializable, IXmlSerializable
public class MarshalByValueComponent :
IComponent, IDisposable, IServiceProvider
Your code block would be represented under the hood as shown below, so it guarantee that Dispose() method will be called:
{
DataTable dt = Admin_User_Functions.Admin_KitItems_GetItems()
try
{
// .. code inside using statement
}
finally
{
if (dt != null)
((IDisposable)dt).Dispose();
}
}
See MSDN for more details: using Statement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With