【发布时间】:2012-03-19 23:45:30
【问题描述】:
我有以下用 C++ 和 C# 编写的代码
int i=0;
++i = 11;
这个C#编译器带来错误后
The left-hand side of an assignment must be a variable, property or indexer
但 C++ 编译器生成此代码时没有错误,我得到了 11 的值 i 的结果。造成这种差异的原因是什么?
【问题讨论】:
-
题外话:为什么要递增,然后直接设置为11?增量没有意义。
-
这段代码有什么用?
-
someArray[++i] = 11会更有意义。 -
这对我来说很有趣。 @mesiesta 正确解释了为什么会这样。
标签: c# c++ int increment language-specifications