[英]System.Linq and IEnumerable Group Help
I'm just getting my feet wet with Linq and IEnumerable, and I'm needing help in trying to determine if my objects contain matches for a card game. 我只是想用Linq和IEnumerable弄湿我的脚,并且在确定我的对象是否包含纸牌游戏的匹配方面需要帮助。 I think if I get the first one figured out, the other match checking I need to do will fall in place.
我认为,如果我弄清楚了第一个,我需要做的其他比赛检查将就位。
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?
}
To get the number of groups: 要获取组数:
cardValueGroups.Count()
To make sure they all have exactly three cards: 为了确保他们都有正好三张牌:
cardValueGroups.All(g => g.Count() == 3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.