Using more than one condition in linq's where method

前端 未结 7 1455
南方客
南方客 2020-12-15 15:44

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

7条回答
  •  盖世英雄少女心
    2020-12-15 16:00

    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");
    

提交回复
热议问题