数据表里面用什么?

发布于 2024-12-18 18:29:16 字数 325 浏览 2 评论 0原文

我已在 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

enter image description here

How is that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月隐月明月朦胧 2024-12-25 18:29:16

System.Data.DataTable 扩展了 System.ComponentModel.MarshalByValueComponent,并且 MarshalByValueComponent 实现了 IDisposable

Reflector 不会显示基类型的方法,除非它们在派生类型中被重写。

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.

随风而去 2024-12-25 18:29:16

DataTable 继承自 MarshalByValueComponent 类,该类实现了 IDisposable 接口(见下文),C# 允许为派生类的实例调用基类公共方法。

public class DataTable : MarshalByValueComponent, 
    IListSource, ISupportInitializeNotification, 
    ISupportInitialize, ISerializable, IXmlSerializable

public class MarshalByValueComponent : 
    IComponent, IDisposable, IServiceProvider

您的代码块将在底层显示,如下所示,因此它保证将调用 Dispose() 方法:

{
  DataTable dt = Admin_User_Functions.Admin_KitItems_GetItems()

  try
  {
     // .. code inside using statement
  }
  finally
  {
    if (dt != null)
      ((IDisposable)dt).Dispose();
  }
}

有关更多详细信息,请参阅 MSDN:using 语句

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

只为守护你 2024-12-25 18:29:16

你为什么要尝试处理数据表?如果您确实希望发生这种情况,则应该将其从其数据集中删除。

Why are you trying to dispose of the DataTable? You should delete it from its DataSet if you really want this to happen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文