There is an array, for example:

var x = new [] {1,2,3,4,5,6,7,8}; 

It is necessary to find the difference between adjacent elements, respectively:

 {1,2,3,4,5,6,7,8} -> {1,1,1,1,1,1,1} 

How can this be implemented by regular means?

    2 answers 2

    For example, like this: x.Zip(x.Skip(1), (first, second) => second - first) .

    • Thank you for what you need! - ExModE

    Another option using Aggregate

     var result = x.Skip(1).Aggregate(new { prev = x[0], result = Enumerable.Empty<int>() }, (acc, cur) => new { prev = cur, result = acc.result.Concat(new[] { cur - acc.prev }) }, a => a.result.ToArray() );