Let's say I have a dictionary declared as follow:
Dictionary<string, IData> map;
I want to get all the values with the keys containing a specific substring with for example a function like
public IEnumerable<IData> GetContains(string pattern) {}
And I figured how to obtain a list of keys matching the pattern using
var result = mapData.Keys.Where(a => a.Contains(pattern)).ToArray()
but I cannot figure out how to reuse the returned keys to get all the corresponding values in one query.
You can use Where on your Dictionary instead of the Keys collection then get the values with Select:
mapData.Where(kvp => kvp.Key.Contains(pattern)).Select(kvp => kvp.Value);
                        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