1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > C#陷阱int i = 10; i += i++; i =

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

时间:2021-12-03 05:14:24

相关推荐

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

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++; (); (); }

编译器告诉我,结果是20。为什么!我错了吗?我开始纳闷了。我赶紧用VC()重新编了一段测试代码,如下:

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)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。