This question was asked at interview.I need to have running total (only using Aggregate() )
from array
(i.e)
int[] array={10,20,30};
Expected output
10
30
60
when i use Aggregate (I applied some worst logic)
array.Aggregate((a, b) => { Console.WriteLine(a + b); return (a + b); });
1) It prints 30,60
,for me there is no use of return (a+b).
2) In order to print 10
, i have to modify the array by adding element zero
(i.e) {0,10,20,30}.
Is there any neat work could turn it out?