Reputation: 23
I have created a dictionary with Tuples as keys and a enumerator as value.
mKeyValue.Add(Tuple.Create(lineCount,columnID),(E)style);
mKeyValue
is the dictionary.
static Dictionary<Tuple<int,int>,E> mKeyValue = new Dictionary<Tuple<int,int>,E>();
Now how to access elements in this dictionary? I used something like this,
mKeyValue[Tuple<lineCount,columnID>];
but it doesn't work.
Upvotes: 2
Views: 1903
Reputation: 77876
If you already have a Tuple<int,int>
defined then use that as key like mKeyValue[t];
Tuple<int,int> t = Tuple.Create(1, 1);
mKeyValue.Add(Tuple.Create(1, 1), (E)21);
var data = mKeyValue[t];
Upvotes: 1
Reputation: 49260
It's no different than usage with any other type of key. You need to pass an instance of the type, not the type (declaration) itself to the indexer.
You wouldn't say myKeyValue[int]
, for a Dictionary<int, ...>
, when you really wanted myKeyValue[5]
. Just the the key looks a little more "complicated" in this case.
Example:
// Lookup entry for LineCount = 1, ColumnID = 4711
var value = myKeyValue[Tuple.Create(1, 4711)];
Basically, just like you did when adding an entry with Dictionary<>.Add(...)
.
Upvotes: 2