i++ 和 ++i 有什么区别? [英] What is the difference between i++ and ++i?
问题描述
我已经看到它们都被用在许多 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 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!