I was trying out using Tasks for multithreading and here is the oddity I came across:
tasks[0] = Task.Run(() => SumNumbers(0, end));
tasks[1] = Task.Run(() => SumNumbers(1, end));
for (int i = 0; i <= 1; i++)
{
tasks[i] = Task.Run(() => SumNumbers(i, end));
}
The first two lines return correct results, whereas the solution with cycles doesn't. Is there an explanation to this?