繁体   English   中英

System.Linq和IEnumerable组帮助

[英]System.Linq and IEnumerable Group Help

我只是想用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?
}

要获取组数:

cardValueGroups.Count()

为了确保他们都有正好三张牌:

cardValueGroups.All(g => g.Count() == 3)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM