IEqualityComparer and GetHashCode in C#

  • Thread starter Thread starter Arash_89
  • Start date Start date
A

Arash_89

Guest
Hello,

I should return the following code but How can write these? because we can return one of these.

return obj.Name.GetHashCode();


and

return obj.Family.GetHashCode();


using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;

namespace ConsoleApp2
{
class CustomerNameComparer : IEqualityComparer<Customer>
{
public bool Equals(Customer x, Customer y)
{
return (x.Name == y.Name) && (x.Family == y.Family);
}

public int GetHashCode([DisallowNull] Customer obj)
{
return obj.GetHashCode();
}
}
}

Continue reading...
 
Back
Top