I am trying to grab all the items in the dictionary based on given string which matches partially or fully.
I tried the following code but doesn’t seems to work
a.Where(d => d.Value.Contains(text)).ToDictionary(d => d.Key, d => d.Value);
Can you please tell me how to achieve this ?
The code you’ve given should work absolutely fine, assuming you really wanted to find entries where the value had a partial match. If you’re seeing something else, I suspect your diagnostics are flawed. If you wanted to find entries where the key had a partial match, you just want to swap
for
Short but complete program demonstrating the code you’ve given working:
Output: