Hi there,
Just wondering what is the correct way of implementing the comparison
operator in c#
operator==
My problem is when one or more of the objects is null,
I've cast to object to try compare them for null, trying to compare on
AlarmProfile objects will recrusivly call my comparison operator so this is
not an option.
code......
public static bool operator==(AlarmProfile lhs, AlarmProfile rhs)
{
object objLeft = lhs as object;
object objRight = rhs as object;
if (objLeft == null)
{
if (objRight == null)
return true;
else
return false;
}
return lhs.Equals(rhs);
}
public override bool Equals(object obj)
{
AlarmProfile rhs = (AlarmProfile)obj;
if (rhs == null)
return false;
return this.ProfileId == rhs.ProfileId;
}
So I'm cheking for null all over the place, it this correct design?
thanks in advance
Brian.