c# - Listbox contains does not find item, cannot remove an item -


i add items list box so:

foreach(myobject object in listofobjects) {     mylistbox1.add(object); }  foreach(myobject object in listofobjectstwo) {     mylistbox2.add(object); } 

further on, want remove couple of items given specific condition. do:

foreach(myobject object in listofobjects3) {     mylistbox1.items.remove(object);     mylistbox2.items.remove(object); } 

this seems work mylistbox1 not mylistbox2. when debug, can see item there , has exact same properties 1 i'm trying remove. when try check if listbox contains item im trying remove, returns false.

i can't seem make sense of it.

i c# lists operation in way required compare objects use equals or gethashcode methods. in case equals , default implementation wont check properties values verify if passed argument object in list consider if have same instance in list or 2 different instances happened have same properties. (the helpful vs option make object id mark instance number)

if case should consider overriding equals method or find instance want delete linq example , pas object remove method.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -