本文介绍了使用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++]);

推荐答案



首先评估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




首先评估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




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 ++时的评估顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 18:13