我已经看到它们都被用在许多 C# 代码中,我想知道什么时候使用 i++ 或 ++i (i++>i 是一个数字变量,如 int、float、double 等).有谁知道吗?
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 like int, float, double, etc). Anyone who knows this?
推荐答案奇怪的是,其他两个答案似乎没有拼写出来,这绝对值得一提:
i++ 的意思是'告诉我 i 的值,然后递增'
i++ means 'tell me the value of i, then increment'
++i 表示'增加i,然后告诉我值'
++i means 'increment i, then tell me the value'
它们是前增量、后增量运算符.在这两种情况下,变量都会递增,但如果你在完全相同的情况下取两个表达式的值,结果会有所不同.
They are Pre-increment, post-increment operators. In both cases the variable is incremented, but if you were to take the value of both expressions in exactly the same cases, the result will differ.
更多推荐
i++ 和 ++i 有什么区别?
发布评论