删除 List中的元素位于元组中的
我有一个 Tuple
,它包含列表中的相同对象,当将 List
中的对象添加到我希望的元组时从 List
中删除它们。
我确信使用 Lamba & 可以轻松做到这一点。 Linq:
//these objects contain some cards
List<Card> cards;
Tuple<Card, Card> ownedcards;
cards.Select(c => ownedcards); //select owned cards from card collection...
但是如何删除那些选定的卡呢?没有删除函数可以获取要删除的项目列表吗?我必须使用 ForEach 吗?
I have a Tuple<T1, T2>
which contains the same object that are in a List, when adding the objects from the List<T>
to the tuple I wish to remove them from the List<T>
.
I am convinced that I can do this easily using Lamba & Linq:
//these objects contain some cards
List<Card> cards;
Tuple<Card, Card> ownedcards;
cards.Select(c => ownedcards); //select owned cards from card collection...
but how do I remove those selected cards? There is no Remove function that takes a list of items to remove? Do I have to use ForEach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Tuple
不是一个集合,它是一个元组,这意味着它包含T1
中的一项和T2
中的一项。您无法向元组添加某些内容,只能更改属性。请描述您到底想要实现什么,因为您当前的想法是不可能的。
A
Tuple<T1, T2>
isn't a collection, it is a tuple, meaning it holds one item ofT1
and one ofT2
. You can't add something to the tuple, you just can change the properties.Please describe what exactly you want to achieve, as your current idea isn't possible.