tagged [equality]

Tuple == Confusion

Tuple == Confusion Suppose I define two tuples: If I try to compare the tuples, I get different results ``` bool result1 = (tuple1 == tuple2); // FALSE bool result2 = tupl

22 Mar at 16:39

(.1f+.2f==.3f) != (.1f+.2f).Equals(.3f) Why?

(.1f+.2f==.3f) != (.1f+.2f).Equals(.3f) Why? My question is about floating precision. It is about why `Equals()` is different from `==`. I understand why `.1f + .2f == .3f` is `false` (while `.1m + .2...

27 Feb at 19:45

Why the compiler emits box instructions to compare instances of a reference type?

Why the compiler emits box instructions to compare instances of a reference type? Here is a simple generic type with a unique generic parameter constrained to reference types: The generated by csc.exe...

18 Jan at 05:20

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

What's the difference between equal?, eql?, ===, and ==?

What's the difference between equal?, eql?, ===, and ==? I am trying to understand the difference between these four methods. I know by default that `==` calls the method `equal?` which returns true w...

8 Sep at 16:34

.NET Dictionaries have same keys and values, but aren't "equal"

.NET Dictionaries have same keys and values, but aren't "equal" This test fails: ``` using Microsoft.VisualStudio.TestTools.UnitTesting; [TestMethod()] public void dictEqualTest() { IDic...

8 Feb at 01:47

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

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

LINQ Select Distinct with Anonymous Types

LINQ Select Distinct with Anonymous Types So I have a collection of objects. The exact type isn't important. From it I want to extract all the unique pairs of a pair of particular properties, thusly: ...

Why does ((object)(int)1).Equals(((object)(ushort)1)) yield false?

Why does ((object)(int)1).Equals(((object)(ushort)1)) yield false? I have the Situation that I have an `object` which I want to check for equality with another `object`. A Problem occurs when `a = 1 (...

14 Aug at 10:21

What is an elegant way to check if 3 variables are equal when any of them can be a wildcard?

What is an elegant way to check if 3 variables are equal when any of them can be a wildcard? Say I have 3 `char` variables, `a`, `b` and `c`. Each one can be `'0'`, which is a special case and means i...

30 Apr at 12:35

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

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

C# .Equals(), .ReferenceEquals() and == operator

C# .Equals(), .ReferenceEquals() and == operator My understanding of these three was: - `.Equals()` tests for data equality (for the lack of a better description). `.Equals()` can return True for diff...

6 Oct at 05:2

Two different "strings" are the same object instance?

Two different "strings" are the same object instance? The code is pretty self explanatory. I expected when I made `a1` and `b1` that I was creating two different string instances that contain the same...

28 May at 04:57

Why String.Equals is returning false?

Why String.Equals is returning false? I have the following C# code (from a library I'm using) that tries to find a certificate comparing the thumbprint. Notice that in the following code both `mycert....

23 Sep at 15:29

What is the best way to check two List<T> lists for equality in C#

What is the best way to check two List lists for equality in C# There are many ways to do this but I feel like I've missed a function or something. Obviously `List == List` will use `Object.Equals()` ...

17 Jul at 10: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

Should I use a concatenation of my string fields as a hash code?

Should I use a concatenation of my string fields as a hash code? I have an Address class in C# that looks like this: ``` public class Address { public string StreetAddress { get; set; } publ...

How to check if two Expression<Func<T, bool>> are the same

How to check if two Expression> are the same Is it possible to find out if two expressions are the same? Like given the following four expressions: Then, at least can see

23 Mar at 15:8

Reference equality performance difference? ((object)obj1 == (object)obj2) vs. object.ReferenceEquals( obj1, obj2 )

Reference equality performance difference? ((object)obj1 == (object)obj2) vs. object.ReferenceEquals( obj1, obj2 ) Is there extra overhead in using the `object.ReferenceEquals` method verses using `((...

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

Can I overload an == operator on an Interface?

Can I overload an == operator on an Interface? I have an interface like this: and I have multiple classes implementing IFoo. I want to check equality, not based on ReferenceEquality, but two IFoos sho...

21 Feb at 13:2

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

Using a class versus struct as a dictionary key

Using a class versus struct as a dictionary key Suppose I had the following class and structure definition, and used them each as a key in a dictionary object: ``` public class MyClass { } public stru...

15 May at 03:40