dotnetdev dotnetdev - 1 year ago 95
C# Question

Using more than one condition in linq's where method

I have a line of code using where:

codebase.Methods.Where(x => x.Body.Scopes.Count > 5);

How can I insert more than one condition? So I can say
x => predicate && y => predicate


Answer Source

You can roll your separate conditions into a single predicate if you like:

codebase.Methods.Where(x => (x.Body.Scopes.Count > 5) && (x.Foo == "test"));

Or you can use a separate Where call for each condition:

codebase.Methods.Where(x => x.Body.Scopes.Count > 5)
                .Where(x => x.Foo == "test");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download