&是什么QUOT;计数++ QUOT;在C#中返回? [英] What does "count++" return in C#?

查看:124
本文介绍了&是什么QUOT;计数++ QUOT;在C#中返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

恰好碰到了一些代码,这不是做什么,我想它应该。难道其他人认为这应该返回1?是否有一个很好的解释,为什么它不?

Just ran into a bit of code that wasn't doing what I thought it should. Do other people think this should return 1? Is there a good explanation as to why it doesn't??

int count = 0;

count++.ToString(); // Returns 1 no?



我一直以为计数++是一样的计算= + 1 ...

I always thought count++ was the same as count = count + 1...

推荐答案

X ++ 的增量运营商。这意味着,值 X 递增,但的 的(非增量)x值返回(在你的情况下0,到的ToString 应用)

x++ is a post increment operator. It means that the value of x is incremented, but the old (non-incremented) value of x is returned (0 in your case, to which ToString is applied).

要搞定的。你想要的行为,使用的的递增运算符 ++ X

To get the behavior you want, use the pre increment operator ++x.

这篇关于&是什么QUOT;计数++ QUOT;在C#中返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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