This is required for equality:
t.Item2.Equals(key.Item2)
So it depends on T
. If T
is a value type this will return true if the values are equal.
If T
is a reference type then this will only return true if both of Item2
refer to the same instance or if T overrides
Equals` so that different instances can be equated.
Prior to that you’re checking ==
between the two instances of T
. That’s probably redundant, but it’s also going to fail for the same reason. Unless you also override the ==
operator it’s going to check reference types for reference equality.
I’d first remove the ==
check – just use Equals
– and then ensure that you can expect that Equals
to return true when you expect it to. That’s either by ensuring that the T
overrides Equals
to give the behavior you expect, or by ensuring that both are the same instance.
2
solved Reasons Equals() on Tuple could return false [closed]