Consider the following class:
internal class Test {
public int Code { get; set; }
public static bool operator ==(Test lhs, Test rhs) {
if (object.ReferenceEquals(lhs, rhs)) return true;
if (lhs == null || rhs == null) {
return false;
} else {
return lhs.Code == rhs.Code;
}
}
public static bool operator != (Test lhs, Test rhs) {
return !(lhs == rhs);
}
}
What is the outcome of the following test code, and why?
Test test1 = new Test { Code = 42 };
Test test2 = new Test { Code = 42 };
if (test1 != test2) {
Console.WriteLine("different");
} else {
Console.WriteLine("equals");
}