当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > C#陷阱int i = 10; i += i++; i =

ASP.NET
many-to-many多对多映射
.NETRemotingChannelListener
转载李建忠老师的一篇文章
原创ColorComboBox控件
用IDisposable接口释放.NET资源
c#v2.0 扩展特性 翻译1
XPath中如何比较不同类型的对象
用哈希表搜索对象
C#陷阱int i = 10; i += i++; i =
Make a window that pops up from taskbar
获取网站返回的头部信息
自己动手写屏保
在DataGrid中添加Radio单选按钮列
实现性能目标的几种方法
增强.NETFramework中线程的功能
ASP.NET 2.0,写无限级下拉菜单不再难
book_dotnet
用.NET武装你的头脑
准备你的发布阶段
移植到.NET

ASP.NET 中的 C#陷阱int i = 10; i += i++; i =


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 24 ::
收藏到网摘: n/a


参加某公司的笔试时的一道题目: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)