equality

What is the algorithm used by the memberwise equality test in .NET structs?

What is the algorithm used by the memberwise equality test in .NET structs? I would like to know this so that I can use it as the basis for my own algorithm. I am trying to write a recursive memberwise equality test for arbitrary objects (in C#) for testing the logical equality of DTOs. This is considerably easier if the DTOs are struct...

When are two enums equal in C#?

I have created two enums and I know they are not the same but still I think it makes sense they would be equal since their string representation as well as their numeral representation are equal (and even the same...). In other words : I would like the first test to pass and the second one to fail. In reality however, they both fail. ...

Pointer equality in Haskell?

Is there any notion of pointer quality in Haskell? == requires things to be deriving Eq, and I have something which contains a (Value -> IO Value), and neither -> nor IO derive Eq. EDIT: I'm creating an interpreter for another language which does have pointer equality, so I'm trying to model this behavior while still being able to use H...

How can you easily test hash equality in Ruby when you only care about intersecting keys?

Say I have the following hashes: hash_x = { :a => 1, :b => 2 } hash_y = { :b => 2, :c => 3 } I need a chunk of logic that compares the two for equality only taking into consideration intersecting keys. In this example the 'b' key is the only commonality between the two hashes and it's value is set to '2' in both so by that ...

Assert that two java beans are equivalent

This question is close, but still not what I want. I'd like to assert in a generic way that two bean objects are equivalent. In case they are not, I'd like a detailed error message explaining the difference instead of a boolean "equal" or "not equal". ...

Equality Test for Derived Classes in C++

Possible Duplicate: Whats the right way to overload operator== for a class hierarchy? In C++, how can derived classes override the base class equality test in a meaningful way? For example, say I have a base class A. Classes B and C derive from A. Now given two pointers to two A objects, can I test if they are equal (including ...

Entity Framework: Is there a method to compare for equal values of EntityObject?

Is there a simple way to compare two EntityObjects for value-equality. I simply want to check if all the database-values are the same, so I don't care if the EntityKey is different. Is this possible built-in? Or should I just write my own method. I guess Equals() doesn't work as I want it here? ...

Python: Can you make this __eq__ easy to understand?

Hello SO, I have another question for you. I have a python class with a list 'metainfo'. This list contains variable names that my class might contain. I wrote a __eq__ method that returns True if the both self and other have the same variables from metainfo and those variables have the same value. Here is my implementation: def __eq...

Question about Object Identity and Object Equality and String class exception

This is a Java and C# question. We all know that, Object Identity(==) tests whether two objects refer to the same location and Obejct Equality(Equals method) tests whether two different (non identical)objects have the same value .But In case of string object Object Identity and Object Equality are same. For e.g Below two boolean expres...

problem with if statement used to determine function return

Im using an if statement to determine what to return in a function, but it seems to be not working the way i want it to. function DoThis($dogs, $cats){ // do something with dogs, pet them perhaps. $reg = $dogs[0]; $nate = $dogs[1]; if($cats = "dave"){return $reg;} if($cats = "tom"){return $nate;} } $cats is a string (if that helps)...

Is there an effective way to determine whether .Equals on two different but "equal" instances will return true?

I'm attempting to use reflection to determine the result of a call to .Equals on two different but "equal" instances of a type. My method would be something like: public static bool TypeComparesProperties(Type t) { // return true if (an instance of t).Equals(a different instance of t) // will be true if all publicly accessible...

php is not equal to and is not equal,equal to

I keep seeing variations of this: Not equal != Not equal, equal !== Which one is the standard or do they have different meanings? I am guessing the latter also checks the value and the name if it's a string, while the former might just check the value only... ...

Best way to write an or is equal statement

Hello $mostamazingforumforfastanswersever. I have a quick silly question; what is the best way to write this : if ($curpageurl == "www.mysite.com/this" || "www.mysite.com/this/") { echo 'this is the this page'; } and if it isn't, then I need to call while (isset($somevariable) { echo '$somevariable'; } and if that variable isn'...

What's the difference between 'eq' vs '==' in PHP?

Hi, First, I tried searching for different variations of the title I've put for this question, both in StackOverflow and google. I couldn't find a solution. I am fairly new to php. New enough to not know the difference between using eq and == for string comparison! I usually use == to compare strings in PHP. I am comfortable with it. ...

Test for equality to the default value

The following doesn't compile: public void MyMethod<T>(T value) { if (value == default(T)) { // do stuff } } Error: Operator '==' cannot be applied to operands of type 'T' and 'T' I can't use value == null because T may be a struct. I can't use value.Equals(default(T)) because value may be null. What is the proper...

Basic Java question: String equality

public class A { static String s1 = "I am A"; public static void main(String[] args) { String s2 = "I am A"; System.out.println(s1 == s2); } } Above program outputs "true". Both are two different identifiers/objects how the output is "true" ? My understanding is that the JVM will create different referenc...

What's the right way to implement equality in ruby

For a simple struct-like class: class Tiger attr_accessor :name, :num_stripes end what is the correct way to implement equality correctly, to ensure that ==, ===, eql?, etc work, and so that instances of the class play nicely in sets, hashes, etc. EDIT Also, what's a nice way to implement equality when you want to compare based on...

How to distinguish MethodBase in generics

I have a cache based on Dictionary<MethodBase, string> The key is rendered from MethodBase.GetCurrentMethod. Everything worked fine until methods were explicitly declared. But one day it is appeared that: Method1<T>(string value) Makes same entry in Dictionary when T gets absolutely different types. So my question is about better...

How do I use java.util.Locale as a key somewhere?

java.util.Locale is one of those classes where I wonder whether I'm too stupid or the guy who wrote it. Is Mark Davis around? As far as I can see, this class isn't supposed to be used. The internal cache in the class is private. The factory package private. equals() uses == to compare strings. This means that I can't compare instances o...

.net 3.5 List<T> Equality and GetHashCode

I'm implementing IEquatable in a custom class that has a List<T> as a property, like so: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public List<string> Dislikes; public bool Equals(Person p) { if (p == null) { return false; } ...