This question already has an answer here:
- LINQ Convert Dictionary to Lookup 2 answers
I have a Dictionary that has a signature: Dictionary<int, List<string>>
. I'd like to convert it to a Lookup with a signature: Lookup<int, string>
.
I tried:
Lookup<int, string> loginGroups = mapADToRole.ToLookup(ad => ad.Value, ad => ad.Key);
But that is not working so well.
You could use:
(You could use
KeyValuePair
instead of an anonymous type - I mostly didn't for formatting reasons.)It's pretty ugly, but it would work. Can you replace whatever code created the dictionary to start with though? That would probably be cleaner.