Lambda expressions and how to combine them?

前端 未结 4 1356
执念已碎
执念已碎 2020-12-31 05:19

How can I combine two lambda expressions into one using an OR ?

I have tried the following but merging them requires me to pass parameters into the Expressio

4条回答
  •  萌比男神i
    2020-12-31 05:39

    Why not just do:

    Func func1 = (x) => x > 5;
    Func func2 = (x) => x > 10;
    
    List> funcs = new List> { func1, func2 };
    
    var value = 7;
    
    Console.WriteLine(funcs.Any(x => x(value))); // OR
    Console.WriteLine(funcs.All(x => x(value))); // AND
    

    ?

    Saves messing about with 3rd party libraries.

提交回复
热议问题