© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
3 replies
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));
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);
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Ef core value comparer
C#CC# / help
4y ago
Type cannot be found (CS7069) [Answered]
C#CC# / help
4y ago