i have a list of double values...
1.23, 1.24, 1.78, 1,74...
so i want to calculate the differences between the successor -> only adding (negative values should be firstly positive)... above 4 values would be 0,01 +0,53 (-)-0,04 (-) -> to make it positive...
with an for-loop, it is easy... any idea how to solve it with linq?
I'm not sure what you mean about the negative bits, but this might do what you want. It's horrible because it uses side effects, but...
(The first value is skipped because it just gives the difference between the first original value and 0d.)
EDIT: What might be slightly nicer would be an extension method to project based on pairs of elements. This isolates the side-effects in one place, which is fine:
To use this in your particular case, you'd do:
You could use the overload of the Select method that supplies the index to the function, so that you can access the previous value in the array:
Not a perfectly "clean" LINQ solution (Jon's SelectPairs extension looks nicer), but I think that it's the easiest way to form the pairs.