-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathEqualityComparer.cs
More file actions
30 lines (26 loc) · 910 Bytes
/
EqualityComparer.cs
File metadata and controls
30 lines (26 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Collections.Generic;
namespace CodeSamples.Comparing
{
public class EqualityComparer : IEqualityComparer<EqualityComparerSample>
{
public bool Equals(EqualityComparerSample x, EqualityComparerSample y)
{
if (x is null && y is null) return true;
if (x is null || y is null) return false;
return (x.IntProperty == y.IntProperty && x.StringProperty == y.StringProperty);
}
public int GetHashCode(EqualityComparerSample obj)
{
return obj.IntProperty.GetHashCode() ^ obj.StringProperty.GetHashCode();
}
}
public class EqualityComparerSample
{
public int IntProperty { get; set; }
public string StringProperty { get; set; }
public override string ToString()
{
return $"Int = {IntProperty}, String = {StringProperty}";
}
}
}