I\'m interested if there is a way, in LINQ, to check if all numbers in a list are increasing monotonically?
Example
List l
public static bool IsIncreasingMontonically(List list)
where T : IComparable
{
return list.Zip(list.Skip(1), (a, b) => a.CompareTo(b) <= 0)
.All(b => b);
}
Note that this iterates the sequence twice. For a List
, that's not a problem at all, for an IEnumerable
or IQueryable
, that could be bad, so be careful before you just change List
to IEnumerable
.