tagged [equality]

Tuple vs string as a Dictionary key in C#

Tuple vs string as a Dictionary key in C# I have a cache that I implement using a ConcurrentDictionary, The data that I need to keep depends on 5 parameters. So the Method to get it from the cache is:...

Which equals operator (== vs ===) should be used in JavaScript comparisons?

Which equals operator (== vs ===) should be used in JavaScript comparisons? I'm using [JSLint](http://en.wikipedia.org/wiki/JSLint) to go through JavaScript, and it's returning many suggestions to rep...

GetHashCode() for OrdinalIgnoreCase-dependent string classes

GetHashCode() for OrdinalIgnoreCase-dependent string classes I'd like to implement a notion of distint addresses, so I overrode Equals() to test for case-insensitive equality in all of the fields (as ...

23 May at 10:29

String comparison : operator==() vs. Equals()

String comparison : operator==() vs. Equals() > [C#: Are string.Equals() and == operator really same?](https://stackoverflow.com/questions/3678792/c-are-string-equals-and-operator-really-same) For s...

23 May at 11:53

How to test two dateTimes for being the same date?

How to test two dateTimes for being the same date? > [How to compare Dates in C#](https://stackoverflow.com/questions/683037/how-to-compare-dates-in-c-sharp) This code of mine: ...fails even when th...

23 May at 11:54

Comparing boxed value types

Comparing boxed value types Today I stumbled upon an interesting bug I wrote. I have a set of properties which can be set through a general setter. These properties can be value types or reference typ...

23 May at 12:0

What's the difference between IEquatable and just overriding Object.Equals()?

What's the difference between IEquatable and just overriding Object.Equals()? I want my `Food` class to be able to test whenever it is equal to another instance of `Food`. I will later use it against ...

1 Aug at 04:32

Comparing two List<string> for equality

Comparing two List for equality Other than stepping through the elements one by one, how do I compare two lists of strings for equality (in .NET 3.0): This fails: ``` // Expected result. List expect...

When would == be overridden in a different way to .equals?

When would == be overridden in a different way to .equals? I understand the difference between == and .equals. There are plenty of other questions on here that explain the difference in detail e.g. th...

14 Jan at 12:39

String equality with null handling

String equality with null handling I will often use this code to compare a string: This handles the null case first etc. Is there a cleaner way to do string comparison, perhaps with a single method ca...

25 Feb at 15:54

Correct way to override Equals() and GetHashCode()

Correct way to override Equals() and GetHashCode() I have never really done this before so i was hoping that someone could show me the correct what of implementing a override of Except() and GetHashCo...

28 Feb at 14:37

Comparing two string arrays in C#

Comparing two string arrays in C# Say we have 5 string arrays as such: Is there a method to compare these strings to each other without looping through them in C# such that only a and c would

30 Nov at 07:2

Is there a difference between "==" and "is"?

Is there a difference between "==" and "is"? My [Google-fu](https://english.stackexchange.com/questions/19967/what-does-google-fu-mean) has failed me. In Python, are the following two tests for equali...

15 Jan at 17:51

Compare object instances for equality by their attributes

Compare object instances for equality by their attributes I have a class `MyClass`, which contains two member variables `foo` and `bar`: I have two instances of this class, each of which has identical...

19 Oct at 10:11

Difference between == and === in JavaScript

Difference between == and === in JavaScript What is the difference between `==` and `===` in JavaScript? I have also seen `!=` and `!==` operators. Are there more such operators?

equals vs Arrays.equals in Java

equals vs Arrays.equals in Java When comparing arrays in Java, are there any differences between the following 2 statements? And if so, what are they?

9 Jan at 22:38

Python3 Determine if two dictionaries are equal

Python3 Determine if two dictionaries are equal This seems trivial, but I cannot find a built-in or simple way to determine if two dictionaries are equal. What I want is: ``` a = {'foo': 1, 'bar': 2} ...

17 Mar at 12:20

What is "Best Practice" For Comparing Two Instances of a Reference Type?

What is "Best Practice" For Comparing Two Instances of a Reference Type? I came across this recently, up until now I have been happily overriding the equality operator () and/or method in order to see...

Custom Equality check for C# 9 records

Custom Equality check for C# 9 records From what I understand, records are actually classes that implement their own equality check in a way that your object is value-driven and not reference driven. ...

14 Mar at 20:33

Testing for equality between dictionaries in C#

Testing for equality between dictionaries in C# Assuming dictionary keys and values have their equals and hash methods implemented correctly, what is the most succinct and efficient way to test for eq...

16 Apr at 03:0