How to create predicate dynamically

后端 未结 3 1676
感动是毒
感动是毒 2020-12-17 19:23

Hi i want to create a list based on the search string using predicate expressions.

I have a list of type products contains different names.

List

3条回答
  •  甜味超标
    2020-12-17 19:57

    As I am not sure that predicate instance has an And method, I suggest you use this code:

    var list = list1.AsQueryable();
    foreach (string str in SearchItems)
    {
         list = list.Where(p => p.Name.ToLower().Contains(str.ToLower()));
    }
    listBox1.ItemsSource = list.ToList();
    

提交回复
热议问题