i ++&之间有什么区别? ++ i [英] what is the difference between i++ & ++i
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文