Hashtable with MultiDimensional Key in C#

后端 未结 16 1556
闹比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:29

    You might be able to "double-nest" your hashtables - in other words, your main Dictionary is of type Dictionary>.

    That accomplishes your goal of being able to use the double bracket notation in your first code snippet.

    Of course, the management side is a little trickier. Every time you add an entry, you need to test if the main dictionary contains a dictionary for the primary key, and add a new dictionary if not, then add the secondary key and value to the inner Dictionary.

提交回复
热议问题