keithly + tuple   1

C#/.NET Little Wonders: Tuples and Tuple Factory Methods
Most of you know about IComparable and IEquatable, what you may not know is that there are two sister interfaces to these that were added in .NET 4.0 to help support tuples. These IStructuralComparable and IStructuralEquatable make it easy to compare two tuples for equality and ordering. This is invaluable for sorting, and makes it easy to use tuples as a compound-key to a dictionary (one of my favorite uses)!

Why is this so important? Remember when we said that some folks think tuples are too generic and you should define a custom class? This is all well and good, but if you want to design a custom class that can automatically order itself based on its members and build a hash code for itself based on its members, it is no longer a trivial task! Thankfully the tuple does this all for you through the explicit implementations of these interfaces.
tuple 
july 2011 by keithly

related tags

tuple 

Copy this bookmark:



description:


tags: