In an example, my professor has implemented Equals as follows:
public class Person {
private string dni;
// ...
public override bool Equals(object
One way this
could ==
null
is if you practiced some black magic by overloading the ==
operator. For example, if someone decides that having a null or empty-string dni
is equivalent to a null person:
public static bool operator ==(Person a, Person b)
{
if(String.IsNullOrEmpty(a.dni) && (object)b == null)
return true;
if(String.IsNullOrEmpty(b.dni) && (object)a == null)
return true;
return Object.ReferenceEquals(a, b);
}
Note this is probably a Really Bad Idea.