C#C
C#4y ago
LukeJ

Cannot create comparer [Answered]

I'm trying to make a comparer to pass around but it's refusing to let me define it. Here's the code
Comparer<Card> trumpComparison = new Func<Card, Card, int>((card1, card2) => (card1.suite == trump ? 1 : 0) - (card2.suite == trump ? 1 : 0));

Card in this case being
public readonly record struct Card(Suite suite, Rank rank);

I've tried doing it as a lambda and it complained it wasn't a delegate. So instead I give it a func, and now it's telling me it cannot convert it to a comparer. What am I missing here?
Was this page helpful?