using System.Collections.Generic;
public static void Main()
var d1 = new Dictionary<int, string>();
var d2 = new Dictionary<int, string>();
var d3 = new Dictionary<int, string>();
var d4 = new Dictionary<int, string>();
d1.Add(57, "FiftySeven");
d2.Add(57, "FiftySeven");
d3.Add(57, "Fifty Seven");
d4.Add(5757, "FiftySeven");
Console.WriteLine("1: " + d1.GetValueBasedHashCode(17, 31) + " << Baseline");
Console.WriteLine("2: " + d2.GetValueBasedHashCode(17, 31) + " << Coincidently matches #1 because the key is the same");
Console.WriteLine("3: " + d3.GetValueBasedHashCode(17, 31) + " << Should be different than # 1, but isn't because the key is the same.");
Console.WriteLine("4: " + d4.GetValueBasedHashCode(17, 31) + " << Is (correctly) different than #1, because of a different key. Not b/c of the value");
Console.WriteLine(d1.GetHashCode());
Console.WriteLine(d2.GetHashCode());
public static class EnumerableExtensions
public static TResult[,] ToRectangularArray<TSource, TResult>(this IEnumerable<TSource> source,
Func<TSource, (int, int, TResult)> selector)
throw new ArgumentNullException("source");
var items = source.Select(x => selector(x));
var result = new TResult[items.Select(x => x.Item1).Max(), items.Select(x => x.Item2).Max()];
foreach (var item in items)
result[item.Item1 - 1, item.Item2 - 1] = item.Item3;
internal static int GetValueBasedHashCode<T>(this IEnumerable<T> lst, int seed, int factor)
foreach (var item in lst.AsEnumerable().OrderBy(x => x.GetHashCode()))
hash = (hash * factor) + item.GetHashCode();