int bestCard;
new BestHand<PokerHand> { Test = h => h.HandContainsFourOfAKind(out bestCard),
Rank = Ranking.FourOfAKind,
BestCard = bestCard },
This code won't work, because HandContainsFourOfAKind
was never called, and so nothing was assigned to bestCard
.
I'm only interested in bestCard when the rule matched. It is used for when there is a draw between two players. E.G. H= 22KJJ -> best card is Jack, not king
So, you want BestCard
to be assigned only when Test
is invoked? This will do.
var hand = new BestHand<PokerHand> {Rank = Ranking.FourOfAKind};
hand.Test = h =>
{
int bestCard; //var local to the lambda's scope
bool contains = h.HandContainsFourOfAKind(out bestCard);
hand.BestCard = bestCard;
return contains;
};