, , , . a , , .
:
Loop Backwards:
, Collection(Of T) ( List(Of T), list RemoveAll, ).
-. , .
<Extension()>
Public Sub RemoveEach(Of T)(ByRef col As Collection(Of T),
ByVal match As Func(Of T, Boolean))
For i = col.Count - 1 To 0 Step -1
If match(col(i)) Then col.RemoveAt(i)
Next
End Sub
:
Dim col = New Collection(Of Integer)({1, 2, 3, 4}.ToList)
col.RemoveEach(Function(i) (i Mod 2) = 0)
'Produces list of 1 & 3
:
, RemoveAt Remove, , . , For Loop, ToList , . , , . , , , .
<Extension()>
Public Sub RemoveEachObject(Of T)(ByRef col As Collection(Of T),
ByVal match As Func(Of T, Boolean))
For Each o As T In col.ToList()
If match(o) Then col.Remove(o)
Next
End Sub
foreach.