tagged [equality]

What does this overload mean?

What does this overload mean? Can someone explain me what does this overload mean? I have never seen Object.ReferenceEquals in overloa

12 Jan at 07:32

Should an implementation of IEqualityComparer.Equals allow null values?

Should an implementation of IEqualityComparer.Equals allow null values? I have a custom generic data structure that includes a Find method: I got a report recently from a client who said that i

19 Mar at 14:6

How do you test to see if a double is equal to NaN?

How do you test to see if a double is equal to NaN? I have a double in Java and I want to check if it is `NaN`. What is the best way to do this?

24 Dec at 08:14

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'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

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

Why do these two comparisons have different results?

Why do these two comparisons have different results? Why does this code return true: but this code returns false:

15 Jan at 13:55

Null checking is ambiguous for a class with several overrides for == operator

Null checking is ambiguous for a class with several overrides for == operator I have a class with two overrides for == operator, to compare it to other instances of this class, and to compare to insta...

What is the difference between using IEqualityComparer and Equals/GethashCode Override?

What is the difference between using IEqualityComparer and Equals/GethashCode Override? When i am using dictionaries sometimes I have to change the default Equals meaning in order to compare Keys. I s...

Equality between two enumerables

Equality between two enumerables I have two enumerables with the exact same reference elements, and wondering why Equals wouldn't be true. As a side question, the code below to compare each element wo...

20 May at 14:19

Why is this code throwing an InvalidOperationException?

Why is this code throwing an InvalidOperationException? I think that my code should make the `ViewBag.test` property equal to `"No Match"`, but instead it throws an `InvalidOperationException`. Why is...

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

== vs Equals in C#

== vs Equals in C# What is the difference between the evaluation of == and Equals in C#? For Ex, but Edited:

19 Mar at 14:47

Comparing two structs using ==

Comparing two structs using == I am trying to compare two structs using equals (==) in C#. My struct is below: ``` public struct CisSettings : IEquatable { public int Gain { get; private set; } pu...

4 Mar at 10:9

(.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

How do I compare strings in Java?

How do I compare strings in Java? I've been using the `==` operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into `.equals()` instead, and it fixe...

23 Jan at 13:36

Resharper suggestion: check for reference equality instead

Resharper suggestion: check for reference equality instead I don't understand why Resharper suggest me to "check for reference equality instead" in this code: Why this should be better: ------------ED...

30 Nov at 15:35

Is "(float)integer == integer" guaranteed to be equal in C#?

Is "(float)integer == integer" guaranteed to be equal in C#? While "we all know" that `x == y` can be problematic, where `x` and `y` are floating point values, this question is a bit more specific: No...

27 Sep at 20:20

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

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

Compare PropertyInfo from Type.GetProperties() and lambda expressions

Compare PropertyInfo from Type.GetProperties() and lambda expressions While creating my testing framework I've found a strange problem. I want to create a static class that would allow me to compare o...

11 Apr at 20:38

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

Determine if 2 lists have the same elements, regardless of order?

Determine if 2 lists have the same elements, regardless of order? Sorry for the simple question, but I'm having a hard time finding the answer. When I compare 2 lists, I want to know if they are "equa...

15 Jan at 04:30

TypeDelegator equality inconsistency?

TypeDelegator equality inconsistency? Consider the following code: ``` class MyType : TypeDelegator { public MyType(Type parent) : base(parent) { } } class Program { static vo...

3 Oct at 09:34

Implementing a geographic coordinate class: equality comparison

Implementing a geographic coordinate class: equality comparison I 'm integrating a geographic coordinate class from CodePlex to my personal "toolbox" library. This class uses `float` fields to store l...

21 Jul at 11:59