Is it possible to use LINQ to check if all numbers in a list are increasing monotonically?

前端 未结 8 2843
旧巷少年郎
旧巷少年郎 2021-02-20 17:14

I\'m interested if there is a way, in LINQ, to check if all numbers in a list are increasing monotonically?

Example

List l         


        
8条回答
  •  Happy的楠姐
    2021-02-20 18:05

    By using an Enumerable.Aggregate method:

    list1.Aggregate((a, i) => a > i ? double.MaxValue : i) != double.MaxValue;
    

提交回复
热议问题