I need to write a method that will take two employee objects as input parameters and compare their ID's to determine whether or not they match.
It's incomplete at the moment; but so far, I have an Employee class that inherits first and last name properties from a "Person" class, and has ID as its own property. I'm writing the method in the employee file and have already instantiated 2 example employees in my program. As for overloading the ==, I'm running into an error that says "Employee" defines operator == but does not override Object.Equals." It also says I need to define "!=", but I'm confused on how to set up the != overload when it doesn't even figure into this method.
I've seen two ways of doing a compare method, one that returns true or false, and another that simply writes "match" to the console. Either of those would work for my purposes, but I can't figure out a workaround for the errors or how I'd change the code in this situation in order to determine a match between 2 employee ID's. Here is my code below; I'd appreciate any input on what may be going wrong! (I have a feeling it may be very off). I'm also unsure of how to call the method but I'm currently trying to figure it out.
Program file:
namespace OperatorOverload
{
class Program
{
static void Main(string[] args)
{
Employee example = new Employee();
example.FirstName = "Kitty";
example.LastName = "Katz";
example.ID = 24923;
Employee example2 = new Employee();
example2.FirstName = "John";
example2.LastName = "Dudinsky";
example2.ID = 39292;
Console.ReadLine();
}
}
}
Employee Class:
namespace OperatorOverload
{
class Employee : Person
{
public int ID { get; set; }
public static bool operator==(Employee employee, Employee employee2)
{
if (employee.ID == employee2.ID)
return true;
else
return false;
}
}
}
Person Class:
namespace OperatorOverload
{
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}