Combine Multiple Predicates

后端 未结 7 694
眼角桃花
眼角桃花 2020-12-01 03:32

Is there any way in c# .NET 2.0! to combine multiple Predicates?

Let\'s say I have the following code.

List names = new List

        
相关标签:
7条回答
  • 2020-12-01 04:23

    I guess you could write something like this:

    Func<string, bool> predicate1 = s => s.StartsWith("E");
    Func<string, bool> predicate2 = s => s.StartsWith("I");
    Func<string, bool> combinedOr = s => (predicate1(s) || predicate2(s));
    Func<string, bool> combinedAnd = s => (predicate1(s) && predicate2(s));
    

    ... and so on.

    0 讨论(0)
提交回复
热议问题