Hashtable with MultiDimensional Key in C#

后端 未结 16 1498
闹比i
闹比i 2020-11-27 02:58

I\'m basically looking for a way to access a hashtable value using a two-dimensional typed key in c#.

Eventually I would be able to do something like this



        
16条回答
  •  北海茫月
    2020-11-27 03:53

    I think a better approach is to encapsulate the many fields of your multi-dimensional key into a class / struct. For example

    struct Key {
      public readonly int Dimension1;
      public readonly bool Dimension2;
      public Key(int p1, bool p2) {
        Dimension1 = p1;
        Dimension2 = p2;
      }
      // Equals and GetHashCode ommitted
    }
    

    Now you can create and use a normal HashTable and use this wrapper as a Key.

提交回复
热议问题