Created
October 10, 2020 17:50
-
-
Save ericsampson/84672e210cc3b8c6e6db12af01aa25de to your computer and use it in GitHub Desktop.
C#9 Records with custom Equality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
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
For an interactive example, see this sharplab