I have a generic list object with a property called,
"MarkedForDeletion". During the course of my processing, some of the
objects in the list will get this property set to true and so at the
end I want to loop through my list and remove any object that has this
property set to true.
Currently I have code like this to accomplish this:
List<MyObjectdetails = MyMethodToGetDetails();
MyMethodToMarkDetailsForDeletion();
List<MyObjectfilteredDetails = details.GetRange(0, details.Count);
MyOjbect currentDetail = null;
for (int deleteIndex = 0; deleteIndex < details.Count; deleteIndex++)
{
currentDetail = details[deleteIndex];
if (currentDetail.MarkedForDeletion)
{
filteredDetails.Remove(currentDetail);
}
}
I want to look at replace this for loop with the ForEach method of the
generic list object. However, the problem is that the Action delegate
of this method does not allow me to pass anything other than the
specific object within the list that I'm dealing with. So I don't
know how to build a delegate that will allow me to remove the object
from within the overall list.
Does anyone have any ideas on how to do this?