I  recently had to create a dictionary which needed a multipart key like . To do this I would have to create a custom class  override equals and gethashcode. That’s when someone told I could use Tuple, but weren’t sure it was possible.  Here was the quick sample to try it in F#


let x = [(“naveen”,1),1;(“naveen”,1),2] |> Map.ofList


as expected only one item in the Map

val x : Map<(string * int),int> = map [((“naveen”, 1), 2)]

And the same in C#

[sourcecode language=”csharp”]

Console.WriteLine(Tuple.Create(“Naveen”,1).Equals( Tuple.Create(“Naveen”,1)));


The next step was to actually disassemble Tuple in reflector

The code implements IStructuralComparable.CompareTo and does the comparison for each item. This is one of the reasons why generics is cool.