数据表里面用什么?
我已在 using 块内声明了数据表,该块在作用域末尾调用 Dispose 方法。
using (DataTable dt = Admin_User_Functions.Admin_KitItems_GetItems())
{
...
}
但在反射器中,数据表似乎没有 Dispose
函数
这是怎么回事?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
System.Data.DataTable
扩展了System.ComponentModel.MarshalByValueComponent
,并且 MarshalByValueComponent 实现了IDisposable
。Reflector 不会显示基类型的方法,除非它们在派生类型中被重写。
System.Data.DataTable
extendsSystem.ComponentModel.MarshalByValueComponent
and, MarshalByValueComponent implementsIDisposable
.Reflector would not display the methods of the base type unless they are overriden in the derived type.
DataTable
继承自MarshalByValueComponent
类,该类实现了IDisposable
接口(见下文),C# 允许为派生类的实例调用基类公共方法。您的代码块将在底层显示,如下所示,因此它保证将调用 Dispose() 方法:
有关更多详细信息,请参阅 MSDN:using 语句
DataTable
inherited fromMarshalByValueComponent
class which implementsIDisposable
interface (see below), C# allows calling base class public methods for the instances of derived classes.Your code block would be represented under the hood as shown below, so it guarantee that Dispose() method will be called:
See MSDN for more details: using Statement
你为什么要尝试处理数据表?如果您确实希望发生这种情况,则应该将其从其数据集中删除。
Why are you trying to dispose of the DataTable? You should delete it from its DataSet if you really want this to happen.