I want to compare all the field of 2 instances except their ID (two similar object can have different Id but all other fields should be same). Is there some direct way to do it in C#
Asked
Active
Viewed 38 times
0
-
1Override `.Equals()`. – Nico Schertler Oct 25 '16 at 17:33
-
https://msdn.microsoft.com/en-us/library/bsc2ak47(v=vs.110).aspx – Vivek Nuna Oct 25 '16 at 17:37
-
He should be implementing IComparer and comparing the objects, not overriding equals. – Dispersia Oct 25 '16 at 17:41
-
@Dispersia That's also a good point. Which way to go depends strongly on the use case. It seems the id-oblivious comparison could define the general equality relation for the class. In this case, overriding `.Equals()` is the way to go. If it is not, then it is a custom comparer. – Nico Schertler Oct 25 '16 at 17:59