我正在检查 Windows 窗体 ListBoxCollection 添加方法,在分析过程中,我发现方法add"调用了基础对象中的 Equals 方法为什么这个方法做这个动作?
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 :
我们调用 :System.Windows.Forms.ListBox.ObjectCollection.Add(object item)
We Call :System.Windows.Forms.ListBox.ObjectCollection.Add(object item)
它会调用:System.Windows.Forms.ListBox.ObjectCollection.AddInternal(object item)
and it will Call : System.Windows.Forms.ListBox.ObjectCollection.AddInternal(object item)
它会调用:System.Windows.Forms.ListBox.NativeAdd(object item)
and it will Call : System.Windows.Forms.ListBox.NativeAdd(object item)
它会调用:System.Windows.Forms.ListControl.GetItemText(object item)
and it will call : System.Windows.Forms.ListControl.GetItemText(object item)
它会调用: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, 对象 dataSourceNullValue)
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)
它会调用 :System.Windows.Forms.Formatter.IsNullData(object value, object dataSourceNullValue)
and it will call :System.Windows.Forms.Formatter.IsNullData(object value, object dataSourceNullValue)
最后它会调用:object.Equals(object objA, object objB)
and Finally it will call : object.Equals(object objA, object objB)
which This Method Make My Equal Method too run :
which This Method Make My Equal Method too Run :
WindowsFormsApplication1.Student.Equals(object obj)
WindowsFormsApplication1.Student.Equals(object obj)
并且将发送到我的 Equals 方法(作为 obj)的最后一个参数是 DBNULL 对象!什么是 DBNULL?
and The Last Parameter which Will be Send to My Equals Method (as obj) is a DBNULL Object ! what is a DBNULL ?
因为它需要能够知道什么项目正在触发事件.如果对象是完全相同的对象,选择、编辑、删除就会变得困难和混乱.
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.
这篇关于为什么 listbox1.Items.Add 使用我的对象的 Equals 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!