why listbox1.Items.Add use Equals Method of my Object?

倖福魔咒の 提交于 2019-12-30 16:07:12

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/8703435/why-listbox1-items-add-use-equals-method-of-my-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!