Stephen Gross
Stephen Gross

Reputation: 5714

How to parameterize a linq query?

I've got a data structure that is a list of hash tables, like so:

List<Hashtable> lh = new List<Hashtable>();

And a fairly simple LINQ query for this container:

var query = from h in lh where h["foo"] == "bar" select h;

Is there a way to parameterize the where clause? Something like:

var where_clause = where h["foo"] == "bar";
var query = from h in lh where_clause select h;

Upvotes: 1

Views: 139

Answers (1)

Phil Klein
Phil Klein

Reputation: 7514

Depends on what exactly you're trying to accomplish, but yes you can:

Func<List<Hashtable>, bool> where_clause = h => h["foo"] == "bar";
List<Hashtable> lh = new List<Hashtable>();
var query = lh.Where(where_clause);

Upvotes: 6

Related Questions