equality

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 based on an equality test. consider the following: public class Property<TProp> where TProp : struct, IEquatable<TProp> { public TProp Value; public void SetValue(ObservableObject owner, TProp value) { if (!Value.E...

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 different instances of the same object, and this is the most commonly overridden method. .ReferenceEquals() tests whether or not two objects are the same instance and cannot be overridden. == is t...

Comparing floating-point 0

If foo is of float type, is the following expression valid/recommended? (0.0f == foo * float(0)) Will it have the expected (mathematical) value regardless of foo's value? Does the C++ standard defines the behavior or is it implementation specific? ...

Equals() contract for C# Dictionary / IDictionary vs equals() contract for Java Map

Nostalgic for Collections.unmodifiableMap(), I've been implementing a read-only IDictionary wrapper based on this discussion, and my unit test quickly ran into a problem: Assert.AreEqual (backingDictionary, readOnlyDictionary); fails, even though the key-value pairs match. I played around a little more, and it looks like at least (tha...

Requirements for entities in NHibernate to be used in a HashedSet.

I would like to use the Iesi.Collections HashedSet class for entity collections in NHibernate. The functionality I want is that duplicate entities cannot be added. I would like entities to be considered duplicate if they share the Id (i.e. primary key) field, or, if they have Id == 0 (i.e. unsaved), then certain key properties are compar...