forked from Zamirathe/Uconomy_Essentials
-
Notifications
You must be signed in to change notification settings - Fork 4
/
GroupComparer.cs
35 lines (28 loc) · 1.18 KB
/
GroupComparer.cs
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
31
32
33
34
35
using System.Collections.Generic;
namespace ZaupUconomyEssentials
{
internal class GroupComparer : IEqualityComparer<Group>
{
public bool Equals(Group x, Group y)
{
//Check whether the compared objects reference the same data.
if (ReferenceEquals(x, y)) return true;
//Check whether any of the compared objects is null.
if (ReferenceEquals(x, null) || ReferenceEquals(y, null))
return false;
//Check whether the products' properties are equal.
return x.DisplayName == y.DisplayName && x.Salary == y.Salary;
}
// If Equals() returns true for a pair of objects
// then GetHashCode() must return the same value for these objects.
public int GetHashCode(Group g)
{
//Get hash code for the Name field if it is not null.
var hashGroupName = g.DisplayName == null ? 0 : g.DisplayName.GetHashCode();
//Get hash code for the Salary field.
var hashGroupSalary = g.Salary.GetHashCode();
//Calculate the hash code for the product.
return hashGroupName ^ hashGroupSalary;
}
}
}