public int CompareTo(object obj) { ComparablePair <S, T> op = obj as ComparablePair <S, T>; if (op == null) { return(-1); } var k = Item1.CompareTo(op.Item1); if (k != 0) { return(k); } else { return(Item2.CompareTo(op.Item2)); } }