LoginSignup
29
28

More than 5 years have passed since last update.

複数の Key を持つ Dictionary

Posted at

TKey を Tuple<> にしてあげればいい。
ついでにこんなクラスを書いてみた。

Dictionary.cs
public Dictionary<TKey1, TKey2, TValue>
    : Dictionary<Tuple<TKey1, TKey2>, TValue>
{
    public TValue this[TKey1 key1, TKey2 key2]
    {
        get { return this[Tuple.Create(key1, key2)]; }
        set { this[Tuple.Create(key1, key2)] = value; }
    }
}
29
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
28