简单的aryth问题C# [英] simple arythmetic question C#

查看:71
本文介绍了简单的aryth问题C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int a = 3;

int b = 5;

int c = 40;

< b> int d = c-- - b * a;< / b>

Console.WriteLine($" a = {a},b = {b} c = {c} d = {d }");
$


订单"int d" hadnling是这样的:



  &NBSP; &NBSP; &NBSP; &NBSP; 39&NBSP; &NBSP; 15

int d =(c - ) - (b * a); == 24?不是cource! < b> d = 25< / b>!
$


因为事实上一个例外订单如下:



< b> int d = c-(b * a)< / b> ;;和c--是postdecrement操作并以某种方式丢失


并且c#编辑器将字符串分成这样的



所以这些表达式相等


int d = c-(b * a)  &NBSP; &NBSP; &NBSP; &NBSP;  和 

int d =(c - ) - (b * a)



< b>有人可以解释一下?< / b> 



等等!如果你试图使用,你可以b
$ b QuickWatch on(c-- - b * a),它完成后台程序,< b>更改c< / b>所以当你再次尝试使用它时,结果将是24!因为c已被更改。

< b>我认为它不正确< / b> 

因为QuickWatch应该执行表达式,但是在不同的放在某处,不应该更改变量。

解决方案


您好


感谢您在此处发帖。


>> int d = c-(b * a)   和int d =(c - - ) - (b * a)


对于您的问题,您想知道上述表达式为何相等。


'c- - '的含义是在完成此表达式的执行后递减c。


你可以参考以下的gif来理解它。



如果你想减少c,你可以尝试下面的代码。

 int d =  -  -c  -  b * a; 




祝你好运,


杰克



int a = 3;
int b = 5;
int c = 40;
<b>int d = c-- - b * a;</b>
Console.WriteLine($"a={a}, b={b} c={c} d={d}");

an order of "int d" hadnling is like this :

          39    15
int d = (c--)-(b*a); == 24? of cource not! <b>d=25</b>!

because in fact an exceution order is following:

<b>int d = c-(b*a)</b>; and c-- is postdecrement operation and lost somehow

and the c# editor divides the string like this

so thiese expressons are equal

int d = c-(b*a)           and 
int d = (c--)-(b*a)

<b>Could somebody explain how?</b> 

and moreover!

if you'll try to use QuickWatch on (c-- - b * a), it fulfilles the procedure in the background and <b>changes the c</b> so when you try to use it again, the result will be 24! because the c has being changed.
<b>I believe it is not correct</b> 
because QuickWatch should execute the expression, but in the different place somewhere and shouldn't change the variable.

解决方案

Hi

Thank you for posting here.

>>int d = c-(b*a)   and int d = (c- -)-(b*a)

For your question, you want to know why the above expressions are equal.

The meaning of ‘c- -‘ is to decrement c after the execution of this expression is completed.

You could refer to the following gif to understand it.

If you want to decrement c, you could try the following code.

     int d = - -c - b * a;


Best regards,

Jack


这篇关于简单的aryth问题C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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