What is the algorithm used by the memberwise equality test in .NET structs?

Posted by Damian Powell on Stack Overflow See other posts from Stack Overflow or by Damian Powell
Published on 2009-11-05T13:29:45Z Indexed on 2010/04/29 23:37 UTC
Read the original article Hit count: 267

Filed under:
|

What is the algorithm used by the memberwise equality test in .NET structs? I would like to know this so that I can use it as the basis for my own algorithm.

I am trying to write a recursive memberwise equality test for arbitrary objects (in C#) for testing the logical equality of DTOs. This is considerably easier if the DTOs are structs (since ValueType.Equals does mostly the right thing) but that is not always appropriate. I would also like to override comparison of any IEnumerable objects (but not strings!) so that their contents are compared rather than their properties.

This has proven to be harder than I would expect. Any hints will be greatly appreciated. I'll accept the answer that proves most useful or supplies a link to the most useful information.

Thanks.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about equality