Reputation: 148524
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 ?
Upvotes: 6
Views: 868
Reputation: 7326
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.
Upvotes: 3
Reputation: 62504
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
Upvotes: 3
Reputation: 39013
Why are you trying to dispose of the DataTable? You should delete it from its DataSet if you really want this to happen.
Upvotes: -1