What is the difference between i++ and ++i?

后端 未结 6 2057
暗喜
暗喜 2020-11-21 23:13

I\'ve seen them both being used in numerous pieces of C# code, and I\'d like to know when to use i++ or ++i (i being a number variable

6条回答
  •  后悔当初
    2020-11-21 23:36

    int i = 0;
    Console.WriteLine(i++); // Prints 0. Then value of "i" becomes 1.
    Console.WriteLine(--i); // Value of "i" becomes 0. Then prints 0.
    

    Does this answer your question ?

提交回复
热议问题