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
(.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...
- Modified
- 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...
- Modified
- 18 Jan at 05:20
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...
- Modified
- 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...
- Modified
- 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...
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...
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: ...
- Modified
- 12 Feb at 21:46
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 (...
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...
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 ...
- Modified
- 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} ...
- Modified
- 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...
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...
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....
- Modified
- 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()` ...
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...
- Modified
- 5 Jun at 19:9
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
- Modified
- 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 `((...
- Modified
- 14 Feb at 01:43
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...
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...
- Modified
- 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...
- Modified
- 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...
- Modified
- 15 May at 03:40