为什么 listbox1.Items.Add 使用我的对象的 Equals 方法?

发布于 2024-12-23 13:54:19 字数 1032 浏览 2 评论 0原文

我正在仔细研究 Windows 窗体 ListBoxCollection 添加方法, 在分析过程中我发现方法“add”调用了基础对象中的Equals方法 为什么这个方法要做这个动作?


我使用过“调用堆栈”,我找到了这个答案:

我们调用:System.Windows.Forms.ListBox.ObjectCollection.Add(object item)

,它将调用:System.Windows.Forms.ListBox.ObjectCollection.AddInternal(object item)

,它将调用: System.Windows.Forms.ListBox.NativeAdd(object item)

,它将调用: System.Windows.Forms.ListControl.GetItemText(object item)

,它将调用:System.Windows.Forms.Formatter.FormatObject(对象值,System.Type targetType,System.ComponentModel.TypeConverter sourceConverter,System.ComponentModel.TypeConverter targetConverter,字符串formatString,System.IFormatProvider formatInfo,对象formattedNullValue,对象dataSourceNullValue)

,它将调用:System.Windows.Forms.Formatter.IsNullData(object value, object dataSourceNullValue)

最后它将调用: object.Equals(object objA, object objB)

该方法使我的 Equal 方法也运行:

WindowsFormsApplication1.Student.Equals(object obj)

并且将发送到我的 Equals 方法(作为 obj)的最后一个参数是 DBNULL 对象! 什么是 DBNULL ?

i'm scrutinizing Windows Forms ListBoxCollection Add Method,
during the analyzing i found that the method "add" calls Equals method in base Object
why this method do this action ?


I Have used "Call Stack" and I have Find This Answer :

We Call :System.Windows.Forms.ListBox.ObjectCollection.Add(object item)

and it will Call : System.Windows.Forms.ListBox.ObjectCollection.AddInternal(object item)

and it will Call : System.Windows.Forms.ListBox.NativeAdd(object item)

and it will call : System.Windows.Forms.ListControl.GetItemText(object item)

and it will call : System.Windows.Forms.Formatter.FormatObject(object value, System.Type targetType, System.ComponentModel.TypeConverter sourceConverter, System.ComponentModel.TypeConverter targetConverter, string formatString, System.IFormatProvider formatInfo, object formattedNullValue, object dataSourceNullValue)

and it will call :System.Windows.Forms.Formatter.IsNullData(object value, object dataSourceNullValue)

and Finally it will call : object.Equals(object objA, object objB)

which This Method Make My Equal Method too Run :

WindowsFormsApplication1.Student.Equals(object obj)

and The Last Parameter which Will be Send to My Equals Method (as obj) is a DBNULL Object !
what is a DBNULL ?

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

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

发布评论

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

评论(1

原野 2024-12-30 13:54:19

因为它需要能够知道哪个项目正在触发事件。如果这些对象是完全相同的对象,则选择、编辑、删除变得困难且混乱。

Because it needs to be able to know what item is firing events. If the objects are the exact same object, selection, editing, deletion becomes difficult and confusing.

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