How to remove an element that matches a given criterion from a LinkedList in C #?

I have a LinkedList where Entry has a member called id. I want to remove an entry from the list where id matches the search value. What is the best way to do this? I do not want to use Remove (), because Entry.Equals will compare other members, and I want only a match with the identifier. I hope to do something like this:

entries.RemoveWhereTrue(e => e.id == searchId); 

edit: Can someone reopen this question for me? This is NOT a duplicate - the question, which should be duplicate, concerns the List class. List.RemoveAll will not work - this is part of the List class.

+5
c # data-structures
source share
3 answers
 list.Remove(list.First(e => e.id == searchId)); 
+3
source share

Here's a simple solution:

 list.Remove(list.First((node) => node.id == searchId)); 
+2
source share

Just use the Where extension method. You will receive a new list (IIRC).

+1
source share

All Articles