Combine Multiple Predicates

后端 未结 7 719
眼角桃花
眼角桃花 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:07

    In .NET 2.0, there are anonymous delegates which you can use there:

    List filteredNames = names.FindAll(
       delegate(string s) { return StartsWithE(s) OR StartsWithI(s); }
    );
    

    In fact, you can use it to replace your functions as well:

    List filteredNames = names.FindAll(
       delegate(string s) { return s.StartsWith("E") || s.StartsWith("I"); }
    );
    

提交回复
热议问题