Is there a better way of calling LINQ Any + NOT All?

后端 未结 8 965
走了就别回头了
走了就别回头了 2021-02-18 14:46

I need to check if a sequence has any items satisfying some condition but at the same time NOT all items satisfying the same condition.

For example, for a sequence of 10

8条回答
  •  佛祖请我去吃肉
    2021-02-18 15:14

    You can use the Aggregate method to do both things at once. I would suggest to use an anonymous type for the TAccumulate, containing both counters. After the aggregation you can read both values from the resulting anonymous type.

    (I can't type an example, I'm on my phone)

    See the documentation here: https://msdn.microsoft.com/en-us/library/vstudio/bb549218(v=vs.100).aspx

提交回复
热议问题