Calculate difference from previous item with LINQ

后端 未结 7 554
你的背包
你的背包 2020-11-27 14:50

I\'m trying to prepare data for a graph using LINQ.

The problem that i cant solve is how to calculate the \"difference to previous.

the result I expect is <

7条回答
  •  悲哀的现实
    2020-11-27 15:25

    In C#4 you can use the Zip method in order to process two items at a time. Like this:

            var list1 = list.Take(list.Count() - 1);
            var list2 = list.Skip(1);
            var diff = list1.Zip(list2, (item1, item2) => ...);
    

提交回复
热议问题