开发者

Remove elements in List<T> that are in Tuple<T1,T2>

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:

开发者_如何学Python//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?


cards.RemoveAll(c => c == ownedcards.Item1 || c == ownedcards.Item2)


A Tuple<T1, T2> isn't a collection, it is a tuple, meaning it holds one item of T1 and one of T2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜