if I have a dictionary
<string, List<string>>. (ex. <12345, List<"ABC", "456", "123">>
and I want to pull out the key '12345' where I have "456" in the list of strings for each entry in the list.
So my result would be another list.
Wouldn't this be done with a linq statement?
Wouldn't this be done with a linq statement?
Sure. It won't be efficient, but it's pretty simple:
var input = "456";
var matchingKeys = dictionary.Where(kvp => kvp.Value.Contains(input))
.Select(kvp => kvp.Key);
If you want it to be efficient as well, you should store the reverse mapping too, and update both together.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With