Search code examples
c#collectionsprimary-keyhashtable

Hash table with two primary keys


Using System.Collections how to create a collection with two primary keys ?

I mean new entries with the same combination are avoided but each key can be used with other keys (like combining two primary keys in SQL)


Solution

  • You can simply use a struct, example:

    struct CompositeKey<T1,T2>
    {
      public T1 Item1;
      public T2 Item2;
    }
    

    Then use that as the key.