Remove list items within

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have a generic list of items and need to remove some of these items according to some criteria. I could do this like that:
<div style="color:Black;background-color:White; <pre>
MyList.RemoveAll(<span style="color:Blue; Function(s) s = xxx)
[/code]
But additionaly to remove the item from the list I also want to something else with the item, eg adding it to a DeletedItemList. Can I achieve this using an inline function as done above. Right now, I do it like in the code below. Maybe there is an even
better option how to do this?
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Module Start
<span style="color:Blue; Public MyListDeleted <span style="color:Blue; As <span style="color:Blue; New List(Of <span style="color:Blue; String)

<span style="color:Blue; Sub Main()

<span style="color:Blue; Dim myList <span style="color:Blue; As <span style="color:Blue; New List(Of <span style="color:Blue; String)

myList.Add(<span style="color:#A31515; "A")
myList.Add(<span style="color:#A31515; "BB")
myList.Add(<span style="color:#A31515; "CCC")
myList.Add(<span style="color:#A31515; "DDDD")

myList.RemoveAll(<span style="color:Blue; AddressOf RemovePredicate)

Console.WriteLine(<span style="color:Blue; String.Format(<span style="color:#A31515; "MyList contains {0}", myList.<span style="color:Blue; Count.ToString))
Console.WriteLine(<span style="color:Blue; String.Format(<span style="color:#A31515; "MyList contains {0}", MyListDeleted.<span style="color:Blue; Count.ToString))
Console.ReadKey()
<span style="color:Blue; End <span style="color:Blue; Sub

<span style="color:Blue; Public <span style="color:Blue; Function RemovePredicate(s <span style="color:Blue; As <span style="color:Blue; String) <span style="color:Blue; As <span style="color:Blue; Boolean
<span style="color:Blue; If s.Length > 2 <span style="color:Blue; Then
MyListDeleted.Add(s)
<span style="color:Blue; Return <span style="color:Blue; True
<span style="color:Blue; Else
<span style="color:Blue; Return <span style="color:Blue; False
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Function
<span style="color:Blue; End <span style="color:Blue; Module
[/code]
Thank you!<br/>
<br/>


View the full article
 
Back
Top