可能重复:
In C# what is the difference between myInt++ and ++myInt?i ++和++ i有什么区别?
重复:In C# what is the difference between myInt++ and ++myInt?
在.NET中,请。
更新:任何人都可以发布一个示例场景来使用,因为两者看起来都非常类似于我。
可能重复:
In C# what is the difference between myInt++ and ++myInt?i ++和++ i有什么区别?
重复:In C# what is the difference between myInt++ and ++myInt?
在.NET中,请。
更新:任何人都可以发布一个示例场景来使用,因为两者看起来都非常类似于我。
i++
是后增量,意思是这个表达式返回i的原始值,然后增加它。++i
是预增量,这意味着该表达式将i,以及从C#支持这种表达行为返回新值许多语言一边。
使它更清楚一点:
i = 0
print i++ // prints 0 and increases i AFTERWARDS
print i // prints "1"
i = 0
print ++i // increases i FIRST, and then prints it ("1")
print i // prints "1"
正如你可以看到不同的是当变量的值,之前或之后更新的,其读取和当前语句
int i = 0;
Console.WriteLine(++i); // prints 1
Console.WriteLine(i++); // prints 1 also
Console.WriteLine(i); // prints 2
使用
你可以看看下面这个例子..
int a = 0;
int i = 5;
//Value of a: 0, i: 5
a=i++;
//Value of a: 5, i: 6
a=++i;
//Value of a: 7, i: 7
复制http://stackoverflow.com/questions/437026/in-c-what-is-the-d 。差分-敏间,和敏 – devio 2009-07-03 08:37:56