Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two objects .

Tags:

c#

If i have a complex object, what is the best practice pattern to write code to compare 2 instances to see if they are the same

like image 763
leora Avatar asked Jan 04 '09 16:01

leora


People also ask

How do you compare two objects?

The equals() method of the Object class compare the equality of two objects. The two objects will be equal if they share the same memory address. Syntax: public boolean equals(Object obj)

Is a function to comparing the objects?

Comparing objects is easy, use === or Object.is(). This function returns true if they have the same reference and false if they do not.

How do you compare values in objects?

Referential equality JavaScript provides 3 ways to compare values: The strict equality operator === The loose equality operator == Object.is() function.


1 Answers

Implement the IEquatable interface. This defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances. Don't forget to override Equals(object) as well. More information here:

http://msdn.microsoft.com/en-us/library/ms131187.aspx

like image 174
Ray Booysen Avatar answered Sep 27 '22 21:09

Ray Booysen