System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)的问题

来源:互联网 发布:知乎恐龙 编辑:程序博客网 时间:2024/05/02 01:30

今天在学习一段VB.net的代码时看到了这样的语句System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)

百思不得其解,在Google上搜了一把,发现这段语句是C#程序转为VB.net时自动生成的。由于在C#程序中使用了诸如

i++之类得得语句,所以为了防止转换后的VB.net程序传递错误的值,就将源程序中的语句自动转换为如上的复杂的语句了。

下面的两个网址对此有解释。

http://www.telerik.com/community/forums/open-source-projects/code-converter/system-math-max-system-threading-interlocked-increment-k-k-1.aspx

http://stackoverflow.com/questions/1828728/why-use-system-threading-interlocked-decrement-instead-of-minus