why listbox1.Items.Add use Equals Method of my Obj

2019-02-21 06:16发布

问题:

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.