i ++&之间有什么区别? ++ i

编程入门 行业动态 更新时间:2024-10-26 00:26:08
本文介绍了i ++&之间有什么区别? ++ i的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对i ++和++ i感到困惑. 请任何人帮我.

I have confusion with i++ and ++i . Please any one help me.

推荐答案

如果您不确定表达式,则应该花时间研究文档 [ ^ ].牢记这些概念很重要. If you are not sure about expressions then you should spend time studying the documentation[^]. It is important to get these concepts fixed in your mind.

第一种情况 First case int i = 10; int j = i++;

执行后, i的值为11 ,而 j的值为10 . 由于此运算符为POSTincrement,因此分配之后会自动发出通知. 第二种情况

After execution value of i would be 11 and value of j would be 10. As this operator is POSTincrement , increament will be done AFTER the assignement. Second case

int i = 10; int j = ++i;

在执行的值后,我将为11 ,而 j的值将为11 . 由于此运算符是PREincrement,因此分配之前会进行提示.

After execution value of i would be 11 and value of j would be 11. As this operator is PREincrement , increament will be done BEFORE the assignement.

hi 一次看这个 hi once lookat this string[] items = {"a","b","c","d"}; int i = 0; foreach (string item in items) { Console.WriteLine(++i); } Console.WriteLine(""); i = 0; foreach (string item in items) { Console.WriteLine(i++); }

输出将是

output will be

1 2 3 4 0 1 2 3

希望对您有帮助... 谢谢与问候 Sandeep

i hope it helps you... Thanks&&Regards Sandeep

更多推荐

i ++&之间有什么区别? ++ i

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

发布评论

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

>www.elefans.com

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