Hi,
I have a class (MyObjectList) that contains an array of list of objects(MyObject).
At present when I am removing the object I traverse the list to check if parent of the current object(object to be removed) is the same as the object in the list. If it is then I remove it.
However I dont want to traverse the list but I want a reference in the MyObjectList class in such a way that whenevr I have an object in hand to be removed I can directly remove itfrom the list without iterating the entite list. This is pure oops.. Can somebody help?
AlanPosted Sep 13, 2007, 2:50 PM
I imagine you must be traversing the List and then using the RemoveAt() method when you find the index of the object you want to remove
You can avoid this by using the Remove() method which removes the first (or only) occurrence of an object in a List or RemoveAll() method if there's a possibility of several matches:
http://msdn2.microsoft.com/en-us/library/cd666k3e.aspx
http://msdn2.microsoft.com/en-us/library/wdka673a.aspx