Last active
August 11, 2021 02:12
-
-
Save qubitz/90e96027ed36c5ff6a87182c3561b511 to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
using System.Collections.Generic; | |
var data1 = new Data("data1"); | |
var data2 = new Data("data2"); | |
Console.WriteLine(new DataEqualityComparer().Equals(data1, data2)); | |
public record Data(string SomeProp); | |
public class DataEqualityComparer : IEqualityComparer<Data> | |
{ | |
public bool Equals(Data x, Data y) | |
{ | |
return | |
ReferenceEquals(x, y) || // true when: both null, same ref | |
x is null == y is null && // true when: both not null | |
x.SomeProp == y.SomeProp; // true when: equal properties | |
} | |
/// <inheritdoc /> | |
public int GetHashCode( | |
Data obj) | |
{ | |
return HashCode.Combine(obj.SomeProp); | |
} | |
} |
This file contains 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
False |
This file contains 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
{ | |
"version": 1, | |
"target": "Run", | |
"mode": "Debug", | |
"branch": "core-x64" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment