Remove a sublist of objects from a given list

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Good morning.<br/>
My question is relative to the following topics.<br/>
If I have a generic List<Ipacket> and wish to remove a subset of Ipackets in accordance with some constraint (for example a matched given property "sentenceId" of each object), which is the best and stilish approach to do it?
I usually solve the problem by nesting a couple of for() cycles or doing some recursion, but now I would like to use a more C# idiom approach, something like a LINQ query on the List or a RemoveAll(some predicate here).
<br/>
I failed to use RemoveAll because the predicate delegate can accept just the object under exam, not a second parameter with a matching sublist and I wish not to expose in a class property the sublist to remove (always due to my personal too much academic approach
to OOP).
Which would be your best C# approach?
Giuseppe

View the full article
 
Back
Top