Is code that uses the static Object.Equals to check for null more robust than code that uses the == operator or regular Object.Equals? Aren\'t the latter two vulnerable to b
The framework guidelines suggest that you treat Equals
as value equality (checking to see whether two objects represent the same information, i.e. comparing properties), and ==
as reference equality, with the exception of immutable objects, for which you should probably override ==
to be value equality.
So, assuming the guidelines apply here, pick whichever is semantically sensible. If you're dealing with immutable objects, and you expect both methods to produce identical results, I'd use ==
for clarity.