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. 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.