我如何删除从C#中的LinkedList符合给定条件的元素? [英] How do I remove an element that matches a given criteria from a LinkedList in C#?

查看:1599
本文介绍了我如何删除从C#中的LinkedList符合给定条件的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

解决方案

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

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));

这篇关于我如何删除从C#中的LinkedList符合给定条件的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆