I would like to use Dictionary as TKey in another Dictionary. Something similar to python. I tried this but it gives me errors.
Dictionary<Dictionary<string, string>, int> dict = new Dictionary<Dictionary<string, string>, int>(); Dictionary<string, string> dict2 = new Dictionary<string, string>(); dict2['abc'] = 'def'; dict[dict['abc'] = 20;
What error is it giving you? Is it complaining about your missing bracket on line 4?
Line 4 looks like it should be:
However, you probably mean this, since ‘abc’ is not a key of dict:
But
dict2['abc']is astring, when the key of dict is supposed to be aDictionary<string, string>.But let’s re-examine your original goal at this point before going to far down this path. You shouldn’t be using mutable types as dictionary keys in the first place.
This may be the code you’re looking for:
But it’s hard to tell for sure.