Skip to content

Instantly share code, notes, and snippets.

@ericsampson
Created October 10, 2020 17:50
Show Gist options
  • Save ericsampson/84672e210cc3b8c6e6db12af01aa25de to your computer and use it in GitHub Desktop.
Save ericsampson/84672e210cc3b8c6e6db12af01aa25de to your computer and use it in GitHub Desktop.
C#9 Records with custom Equality
Rec a = new Rec{myInt = 1, myStr = "test"};
Rec b = a;
System.Console.WriteLine(a == b);
public record Rec()
{
public int myInt;
public string myStr;
public virtual bool Equals(Rec other) => false;
public override int GetHashCode() => 1;
}
@ericsampson
Copy link
Author

For an interactive example, see this sharplab

@aredfox
Copy link

aredfox commented Oct 10, 2020

Thanks a lot for this, works now and I finally understand it :-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment