tagged [equality]
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...
- Modified
- 5 Aug at 17:43
Why comparing two strings as object causes unexpected result
Why comparing two strings as object causes unexpected result Consider the following piece of code. I understand the equality operator working here that as we have implicitly casted
- Modified
- 13 Jul at 11:52
Generic constraints: Can I test Equality of generic that can be a reference or value type?
Generic constraints: Can I test Equality of generic that can be a reference or value type? I want a single generic class that can accept either reference or value types, and only perform an action bas...
Surprising Tuple (in)equality
Surprising Tuple (in)equality Until today, my understanding of .NET `Tuple` classes had been that they delegate their implementation of `Equals()` to their contents, allowing me to equate and compare ...
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:...
- Modified
- 2 Feb at 12:22
Testing delegates for equality
Testing delegates for equality I'm building a hierarchical collection class that orders magnetic resonance images spatially and arranges them into groupings based on the various acquisition parameters...
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...
- Modified
- 27 Sep at 20:20
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 ...
How do I ignore the UTF-8 Byte Order Marker in String comparisons?
How do I ignore the UTF-8 Byte Order Marker in String comparisons? I'm having a problem comparing strings in a Unit Test in C# 4.0 using Visual Studio 2010. This same test case works properly in Visua...
- Modified
- 26 May at 17:59
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...
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...
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...
- Modified
- 28 Feb at 14:37
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...
- Modified
- 20 Jun at 09:12
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...
- Modified
- 16 Jun at 20:7
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
Why does Object.Equals() return false for identical anonymous types when they're instantiated from different assemblies?
Why does Object.Equals() return false for identical anonymous types when they're instantiated from different assemblies? I have some code that maps strongly-typed business objects into anonymous types...
- Modified
- 31 Aug at 12:56
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...
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...
- Modified
- 11 Apr at 20:38
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. ...