I think that the code below is good. But how can I write it in LINQ? how can I compare Employee type object in linq?
namespace GenericReplacement
{
class Program
{
static void Main(string[] args)
{
EmployeeComparer employeeComparer = new EmployeeComparer();
Employee employee1 = new Employee() { ID = 1, Name = "yusuf", SurName = "karatoprak" };
Employee employee2 = new Employee() { ID = 2, Name = "Ali", SurName = "Yılmaz" };
bool returnValue = employeeComparer.Equals(employee1, employee2);
int returnValueHashCode = employeeComparer.GetHashCode(employee1);
Console.WriteLine("Result: "+returnValue.ToString()+"\n");
Console.WriteLine(returnValueHashCode.ToString());
Console.ReadKey();
}
}
public class EmployeeComparer: EqualityComparer<Employee>
{
public override bool Equals(Employee x, Employee y)
{
return EqualityComparer<Employee>.Default.Equals(x, y);
}
public override int GetHashCode(Employee obj)
{
return EqualityComparer<Employee>.Default.GetHashCode(obj);
}
}
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
public string SurName { get; set; }
}
}