i++ 和 ++i 有什么区别?

编程入门 行业动态 更新时间:2024-10-24 16:27:46
本文介绍了i++ 和 ++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 有什么区别?

本文发布于:2023-07-29 09:00:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239291.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!