I have this code:
static int[] a = {0 , 10 , 20, 30, 40};
public static void Main()
{
for (int i = 0; i < 10; i++){
int[] array = a;
for (int j = 1; j < array.Length; j++)
array[j] += array[j - 1];
Console.WriteLine(array[4]);
}
}
In the console I get the following result:
100
200
350
560
840
But I did not expect this or it is not what I want. I wanted the following result:
100
100
100
100
100
I have no idea why this is happening. How can I solve this?