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()` ...
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
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...
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 ...
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
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
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 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...
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...
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...
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' ...
- Modified
- 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.
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...
- Modified
- 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...
- Modified
- 26 May at 17:59
.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
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...
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
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.
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
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?