For some reason, I thought that if the if condition is false, then any operations in it (especially the condition checker) do not affect the further course of the program, but it turned out that this is not so.
static void Main(string[] args) { int x = 6; Console.WriteLine("Начальное значение x = " + x); if (++x == 6) //блок if не должен выполниться т.к. он ложен { Console.WriteLine("++x = " + x); } if (x++ == 7) { Console.WriteLine("x++ = " + x); } Console.WriteLine("Теперь x = " + x); Console.ReadLine(); } Result:
Начальное значение х = 6 х++ = 8 Теперь х = 8 for some reason it seemed to me logical that if an expression is included in a condition check and the result is false, then it does not seem to change anything.
++expression does not depend on further checks. The expression itself must be evaluated to obtain the result of the condition, and, accordingly, a side effect will occur. Inheritance of C. - alexlzlogging_on... - alexlzif (x++ == 6)" x should remain as it was before the increment. So I gave an analogy with a deleted file, such as it should also remain in place. - Sh4dow