tagged [equality]

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

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

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

4 Mar at 19:59

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

21 Feb at 18:24

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

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

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

What's the fastest way to compare two arrays for equality?

What's the fastest way to compare two arrays for equality? I have two arrays of objects which are likely to have the same values, but in a different order, e.g. I wish to treat these two arrays as equ...

11 Nov at 09:50

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

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

5 Oct at 12:42

Equality comparison between multiple variables

Equality comparison between multiple variables I've a situation where I need to check whether multiple variables are having same data such as I want to check whether x==1 and y==1 z==1 (it may be '1' ...

15 Jul at 10:54

jQuery object equality

jQuery object equality How do I determine if two jQuery objects are equal? I would like to be able to search an array for a particular jQuery object.

5 Jul at 02:22

Comparing XmlDocument for equality (content wise)

Comparing XmlDocument for equality (content wise) If I want to compare the contents of a XMlDocument, is it just like this? I am not checking if they are both the same object reference, but if the CON...

27 May at 19:46

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

.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

Test for equality to the default value

Test for equality to the default value The following doesn't compile: `Operator '==' cannot be applied to operands of type 'T' and 'T'` I can't use `value == null` because `T` may be a struct. I can't...

13 Dec at 09:27

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

Equality with Double.NaN

Equality with Double.NaN I have the following code... Which outputs: What gives? I'm using Double.NaN to indicate that the value doesn't exist, and shouldn't be output.

17 Feb at 19:1

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

How do you compare structs for equality in C?

How do you compare structs for equality in C? How do you compare two instances of structs for equality in standard C?

26 Sep at 20:21