I have a dictionary that contains Product values with properties like description.
In a textbox1_textchanged handler, I want to search the Products in the dictionary that has certain text within the description.
I’ve tried this:
var values = (from pv in mydictionary
where pv.Value.description.Contains(textBox1.Text)
select pv.Value);
This code isn’t working because the second key I pressed values var values is empty.
All the examples I found are searching through the keys but I need to search through the values of the dictionary.
What you have isn’t valid code however. You are trying to filter the values that have a certain description but you’re missing a key element. You need to add the
whereclause to complete it.A better way to write this however would be to just look at the values of the dictionary.
To make it case-insensitive, you could try using
String.IndexOf()since it’s one of the few comparisons that could do the search ignoring the case.