Why does IQueryable.All() return true on an empty collection?

后端 未结 11 1740
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 04:46

So I ran into a situation today where some production code was failing precisely because a method performed exactly as documented in MSDN. Shame on me for not reading the d

11条回答
  •  旧巷少年郎
    2020-12-01 05:30

    If the number of the items that return true is the same as the number of all the items, then return true. Simple as that:

    Driveway.Cars(a => a.Red).Count() == Driveway.Cars.Count()
    

    Related explanation: Why does "abcd".StartsWith("") return true?

提交回复
热议问题