使用i ++时的评估顺序 [英] Evaluation order when i++ is used

查看:54
本文介绍了使用i ++时的评估顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下文中,第二个参数值放在arr2 [2]中。我可以假设第一个也是

放在arr1 [2]而不是arr1 [3]?更一般地说,在C#中,我在什么时候递增?


int i = 2;

func(out arr1 [i],out arr2 [i + ]);

In the following, the second parameter value is put in arr2[2]. Can I assume that the first is also
put in arr1[2] and not arr1[3]? More generally, in C#, at what point is i incremented?

int i=2;
func(out arr1[i], out arr2[i++]);

推荐答案

12月18日下午1:49,Jon < .wrote:
On Dec 18, 1:49 pm, "Jon" <.wrote:

在下文中,第二个参数值放在arr2 [2]中。我可以假设第一个也是

放在arr1 [2]而不是arr1 [3]?更一般地说,在C#中,我在什么时候递增?


int i = 2;

func(out arr1 [i],out arr2 [i + ]);
In the following, the second parameter value is put in arr2[2]. Can I assume that the first is also
put in arr1[2] and not arr1[3]? More generally, in C#, at what point is i incremented?

int i=2;
func(out arr1[i], out arr2[i++]);



首先评估i(对于第一个参数)然后我再次评估

(对于第二个参数)然后i递增。


但是,像这样的代码不会通过任何有价值的代码审查。

这很好,行为是指定的,但它'

可读性方面很糟糕。


Jon

First i is evaluated (for the first argument) then i is evaluated
again (for the second argument) then i is incremented.

However, code like this won''t get past any worthwhile code review.
It''s nice that the behaviour is specified, but it''s awful in terms of
readability.

Jon


谢谢Jon。


出于好奇,我总是在评估之后递增,例如,如果i ++在第一个而不是第二个参数中,那么增量是否仍然发生评价?


Jon

" Jon Skeet [C#MVP]" < sk *** @ pobox.com写了留言

新闻:3d *************************** ******* @ t1g2000p ra.googlegroups.com ...

12月18日下午1:49,Jon < .wrote:
Thanks Jon.

Out of curiosity, is incrementing i always after evaluation, eg if the i++ is in the first rather
than in the second parameter, does the increment still happen after all evaluations?

Jon
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:3d**********************************@t1g2000p ra.googlegroups.com...
On Dec 18, 1:49 pm, "Jon" <.wrote:

在下文中,第二个参数值放在arr2 [2]中。我可以假设第一个是

还是

放入arr1 [2]而不是arr1 [3]?更一般地说,在C#中,我在什么时候递增?


int i = 2;

func(out arr1 [i],out arr2 [i + ]);
In the following, the second parameter value is put in arr2[2]. Can I assume that the first is
also
put in arr1[2] and not arr1[3]? More generally, in C#, at what point is i incremented?

int i=2;
func(out arr1[i], out arr2[i++]);



首先评估i(对于第一个参数)然后我再次评估

(对于第二个参数)然后i递增。


但是,像这样的代码不会通过任何有价值的代码审查。

这很好,行为是指定的,但它'

可读性方面很糟糕。


Jon

First i is evaluated (for the first argument) then i is evaluated
again (for the second argument) then i is incremented.

However, code like this won''t get past any worthwhile code review.
It''s nice that the behaviour is specified, but it''s awful in terms of
readability.

Jon




-

Ignacio Machin
http:// www.laceupsolutions.com

手机&仓库解决方案。

" Jon" < .wrote in message news:OR **************** @ TK2MSFTNGP04.phx.gbl ...
Hi,
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Jon" <.wrote in message news:OR****************@TK2MSFTNGP04.phx.gbl...

谢谢Jon。


出于好奇,我总是在评估后递增,例如,如果i ++

在第一个而不是

比第二个参数,在所有

评估之后,增量是否仍然发生?
Thanks Jon.

Out of curiosity, is incrementing i always after evaluation, eg if the i++
is in the first rather
than in the second parameter, does the increment still happen after all
evaluations?



AFAIK是的。


现在一个更有趣的问题是如果不使用
$ b会发生什么$ b评估后你使用之前评估运算符(++ i)并且做

类似于:


func(out arr1 [++ i], out arr2 [++ i])


再一次,我和Jon一致,这是一个可怕的代码!


AFAIK yes.

Now a more interesting question is what happens if instead of using the
after evaluation you use the before evaluation operator ( ++i) and do
something like :

func(out arr1[++i], out arr2[++i])

Again, I coincide with Jon, that is an horrible code!


这篇关于使用i ++时的评估顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆