O'Reilly logo
  • Zachery Parks thinks this is interesting:

      // Displays 126, 127, 128
      System.Console.WriteLine("{0}, {1}, {2}", ++x, ++x, x);
      // x now contains the value 128.


Cover of Essential C# 5.0


This is a mistake. It should actually display 126, 127, 127. The first ++x will increment x from 125 to 126 and then display the result, the next ++x will increment x to 127 and display that result. However, there is no increment after that and it should just display whatever x holds, which is 127. 128 should never show up here.