using System.Collections.Generic;
SortedDictionary<CustomKey, string> dict = new SortedDictionary<CustomKey, string>();
dict.Add(new CustomKey() { intKey = 1, sortingVariable = 8 }, "1");
dict.Add(new CustomKey() { intKey = 2, sortingVariable = 6 }, "2");
dict.Add(new CustomKey() { intKey = 5, sortingVariable = 12}, "expected value");
dict.Add(new CustomKey() { intKey = 3, sortingVariable = 5 }, "3");
dict.Add(new CustomKey() { intKey = 4, sortingVariable = 4 }, "4");
dict.TryGetValue(new CustomKey() { intKey = 5, sortingVariable = 17} , out res);
public struct CustomKey : IComparable
public override bool Equals(object obj)
return ((CustomKey)obj).intKey == intKey && ((CustomKey)obj).objectKey == objectKey;
public override int GetHashCode()
return intKey.GetHashCode() ^ objectKey.GetHashCode();
public int CompareTo(object obj)
return sortingVariable.CompareTo(((CustomKey)obj).sortingVariable);
public int sortingVariable;
public string otherSortingVariable;