我只是在Linq和IEnumerable中弄湿了,我需要帮助才能确定我的对象是否包含纸牌游戏的匹配项。我想如果我弄清楚了第一个问题,我需要做的另一个匹配检查将会落实到位。
public class Card
{
pubic int Value { get; set; }
public Card(int value)
{
this.Value = value;
}
}
public bool IsCompletedSet(List<Card> cards)
{
var cardValueGroups = cards.GroupBy(card => card.Value);
//How do I determine that there are now exactly two groups of cards
//and that each group contains exactly 3 cards each?
}
答案 0 :(得分:1)
获取组数:
cardValueGroups.Count()
确保他们都有三张牌:
cardValueGroups.All(g => g.Count() == 3)