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
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)
Comparing objects is easy, use === or Object.is(). This function returns true if they have the same reference and false if they do not.
Referential equality JavaScript provides 3 ways to compare values: The strict equality operator === The loose equality operator == Object.is() function.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With