Continued from part 1 and part 2: Care with == and Reference Types One final thing to note is that operator overloads dont behave like overrides. If you use the == operator with reference types without thinking this can be a problem. For example, suppose you have an untyped DataSet ds containing a DataTable dt. … Continue reading Comparing Values for Equality in .NET: Identity and Equivalence (Part 3)

# Category: identity

# Comparing Values for Equality in .NET: Identity and Equivalence (Part 2)

Continued from Part 1: ii) object.Equals(a, b) object.Equals(a, b)): Overview object.Equals(a, b) is a static method on the object class. Jeffery Richter describes it as ‘a little helper method’. It’s easiest to think of it as a method that does some checking for nulls and then calls a.Equals(b). The reason it exists is that if … Continue reading Comparing Values for Equality in .NET: Identity and Equivalence (Part 2)

# Comparing Values for Equality in .NET: Identity and Equivalence (Part 1)

This article is now available on the Code Project at http://www.codeproject.com/dotnet/DotNetEquality.asp Introduction The various ways of comparing two values for equality in .NET can be very confusing. In fact if we have two objects a and b in C# there are at least four ways to compare their identity, plus one operator that looks like … Continue reading Comparing Values for Equality in .NET: Identity and Equivalence (Part 1)