Should I forward the a call to .Equals onto .Equals<T>?
Posted
by
Jaimal Chohan
on Programmers
See other posts from Programmers
or by Jaimal Chohan
Published on 2011-01-31T22:04:42Z
Indexed on
2011/01/31
23:33 UTC
Read the original article
Hit count: 285
c#
|programming-practices
So, I've got you bog standard c# object, overriding Equalsand implementing IEquatable
public override int GetHashCode()
{
return _name.GetHashCode();
}
public override bool Equals(object obj)
{
return Equals(obj as Tag)
}
#region IEquatable<Tag> Members
public bool Equals(Tag other)
{
if (other == null)
return false;
else
return _name == other._name;
}
#endregion
Now, for some reason, I used to think that forwarding the calls from Equals into Equals was bad, no idea why, perhaps I read it a long time ago, anyway I'd write separate (but logically same) code for each method.
Now I think forwarding Equals to Equals is okay, for obvious reasons, but for the life me I can't remember why I thought it wasn't before.
Any thoughts?
© Programmers or respective owner