0

I have a list of multiple values 3,5,10.

Now I want to create a linq .where filter during runtime with the Or operator.

How can I do this using LINQKit? Or with plain linq but I dont think its possible.

E.g. this would be a hardcoded version:

var filter = mydata.Where(v => v.state == "3" || v.state == "5" || v.state == "10");

This would filter mydata array dynamically.

But I do not want it to be hardcoded!

HelloWorld
  • 4,671
  • 12
  • 46
  • 78

1 Answers1

2

You can simply use the Contains method like this:

var filter = mydata.Where(v => list.Contains(v.state));
Yacoub Massad
  • 27,509
  • 2
  • 36
  • 62