3
shouts

Implementing Object Comparison

posted by CygonCygon 236 days, 7 hours, 6 minutes ago
Monday, December 07, 2009 7:12:22 AM GMT

Comparison operators are often implemented poorly in .NET, in the sense that they contain duplicate code or perform certain checks, like a null reference test, multiple times. This article demonstrates a pattern that you can use to implement object comparison in a way that causes zero redundant code and achieves perfect efficiency (no comparison, not even a null check, is performed twice). It also provides a solution for comparison in inherited classes and integrates well with the == and != operators - all again without any redundant code and achieving optimal efficiency.

category: Foundation | clicked: 3 | | source: www.nuclex.org | show counter code

No comments yet, be the first one to post comment.

To post your comment please login or signup