Hi,
my Objects are maontained in a List (of T).
In each TimeCycle I need to check each item and remove it if a criteria is met.
I do hesitate do remove within the main For..Each loop, in order not to make the for..Each stumble.
I came up with two solutions:
Method A
Should be fast in the Main For..Next, however needs a loop to remove.Code:'in main For Each For Each a As myObject in ObjectList .. If Criteria Then RemovList.Add(a) End If Next For Each a As myObject in RemoveList ObjectList.Remove(a) Next
Isn't it possible to do such a Remove without a For Next?
Method B
Nothing to do within Main For..Next, however the Removeall has to be called in each Timecycle. I do believe the removeAll iterates through all items like a For...Next loop.Code:'after Main For Next ObjectList.RemoveAll(AddressOf CriteriaMet) ... 'Elsewhere Private Shared Function CriteriaMet(ByVal a as myObject) As Boolean Return a.someProperty=WhatEver End Function
Any suggestions??




Reply With Quote