In LINQ, is it possible to pass .Where
conditions as parameter?
IList<Object> obj = persons
.Where(p => p.Text.Contains("x") || p.Text.Contains("y"))
.ToList();
So that more than one dynamic conditions
In LINQ, is it possible to pass .Where
conditions as parameter?
IList<Object> obj = persons
.Where(p => p.Text.Contains("x") || p.Text.Contains("y"))
.ToList();
So that more than one dynamic conditions
The single line you have posted is equivalent to the following:
bool filter( Person p )
{
return p.Text.Contains( "x" ) || p.Text.Contains( "y" );
}
IList<Object> obj = persons.Where( filter ).ToList();
I hope this answers your question.