How should I instantiate a nested dictionary with a compare parameter? I can create a single dictionary, but I am unsure how to pas the param when nested.
var single = new ConcurrentDictionary<byte[], ulong>(new ByteArrayComparer());
//Where do I put ByteArrayComparer?
var nested = new ConcurrentDictionary<ulong, ConcurrentDictionary<byte[], ulong>>();
CodePudding user response:
You'd need to specify it in each dictionary you use as a value for an entry in the "outer" dictionary. It's entirely possible for different values to use different comparers:
var nested = new ConcurrentDictionary<ulong, ConcurrentDictionary<byte[], ulong>>
{
{ 123UL, new ConcurrentDictionary<byte[], ulong>(new ByteArrayComparer()) },
{ 456UL, new ConcurrentDictionary<byte[], ulong>(new OtherComparer()) },
};