It's difficult to tell - but that isn't 10,000,000 iterations: it's only 5,000,000 because you increment
i
twice in each loop.
The problem is that the bulk of the loop is a "fixed calculation" so any half decent optimiser will happily take out the loop content (and could easily dispose of the loop itself as well). But...if you are running this in the debugger, then optimisations are pretty much disabled, so it shouldn't be removed.
And no, it's not the number of nano seconds... You print a value you calculate before the loop is even started!, and the Stopwatch class isn't accurate to nanoseconds anyway!
Try this:
int a, b;
a = 1; b = 2;
Stopwatch sw = Stopwatch.StartNew();
for (int i = 0; i < 10000000; i++)
{
int c = (a + b);
}
sw.Stop();
Console.WriteLine("Milliseconds time is: {0}ms", sw.ElapsedMilliseconds);
Console.ReadLine();