C#陷阱int i = 10; i += i++; i =

黑色大妹

黑色大妹

2016-01-29 13:26

C#陷阱int i = 10; i += i++; i =,C#陷阱int i = 10; i += i++; i =

参加某公司的笔试时的一道题目:int i = 10; i += i++; i = ?。当时我写了21。但当我在C#中写了如下代码测试时
static void Main(string[] args) { int i = 10; i += i++; Console.WriteLine(i); Console.Read(); }
编译器告诉我,结果是20。为什么!我错了吗?我开始纳闷了。我赶紧用VC(Visual Studio.net2003)重新编了一段测试代码,如下:
int _tmain(){ int i = 10; i += i++; Console::WriteLine(i); Console::Read(); return 0;}
这次,结果是21。奇怪了啊,为什么同样是i += i++,其结果是不一样的呢?
最终结论:语言差异
C# does have explicit rules around this behavior. (left to right)C++ does not (problem of the C++ language, not the compiler)
展开更多 50%)
分享

猜你喜欢

C#陷阱int i = 10; i += i++; i =

电脑网络
C#陷阱int i = 10; i += i++; i =

|I MISS YOU| |I WANT YOU| |I NEED YOU|

电脑入门
|I  MISS YOU| |I  WANT YOU| |I  NEED YOU|

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

I would cry But I will not lose

电脑入门
I would cry But I will not lose

I know I am not flattering, so I did not who is cumbersome

电脑入门
I know I am not flattering, so I did not who is cumbersome

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

i love you * i miss you *

电脑入门
i love you *  i miss you *

I miss you but I miss you

电脑入门
I miss you but I miss you

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

PHP安全配置之实现安全的两个重点

PHP安全配置之实现安全的两个重点

如何使用PHP和PEAR的Net:Geo定位用户

如何使用PHP和PEAR的Net:Geo定位用户
下拉加载更多内容 ↓