我如何删除从C#中的LinkedList符合给定条件的元素?元素、条件、LinkedList

2023-09-04 10:49:40 作者:记忆很讨厌。

我有一个链表,其中入口有一个成员叫ID。我想删除其中id匹配搜索值列表中的条目。什么是做到这一点的最好方法是什么?我不希望使用remove()方法,因为Entry.Equals将比较其他成员,我只希望匹配的ID。我希望做那种事情是这样的:

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

编辑:我一个人可以重新打开了这个问题?这不是一个重复的 - 它应该的问题是重复的是关于List类。 List.RemoveAll将无法正常工作 - 这是List类的一部分

解决方案

  list.Remove(list.First(E => e.id == searchId));
 

Java LinkedList的原理及应用

I have a LinkedList, where Entry has a member called id. I want to remove the Entry from the list where id matches a search value. What's the best way to do this? I don't want to use Remove(), because Entry.Equals will compare other members, and I only want to match on id. I'm hoping to do something kind of like this:

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

edit: Can someone re-open this question for me? It's NOT a duplicate - the question it's supposed to be a duplicate of is about the List class. List.RemoveAll won't work - that's part of the List class.

解决方案

list.Remove(list.First(e => e.id == searchId));

 
精彩推荐
图片推荐