I have to compare a object with the raw properties of the same class. Meaning, i have to compare those:
struct Identifier
{
string name;
string email;
}
with the two strings name and email. I know i could just create a new Identifier instance for name and email and pass that into equals(). My application has to be very fast and resource-saving.
I know that comparison via hashcode isn't a good way, because as explained here there are collisions. But collisions are okay for me, i just need it to be fast.
So,
1) is comparison via GetHashCode (check if the hashcode of both objects are the same) faster than Equals()?
2) Should i instead creating a new instance of Identifier of the two values for the comparison, make a new method which takes the values directly? e.g.
struct Identifier {
string name;
string email;
bool Equals(string name, string email) {
// todo comparison via hashcode or equals
}
}
I would use the Equals() and GetHashCode() method generated by resharper.