我只是仔细阅读了 System.Collections.Generic.List(Of T).Add(item As T)
的反编译代码使用 ILSpy,我发现了对 __PostIncrement
的调用.我在 VB 中从未听说过这样的事情,所以我做了一些挖掘并发现:
- 在 VB 中,代码是
Me._items(__PostIncrement(Me._size)) = item
. - 在 C# 中,代码是
this._items[this._size++] = item;
使用该语言的实际后增量运算符 - 在 MSIL 中,没有函数调用。它看起来像 C# 后增量一样工作(评论是我的,但我不是 MSIL 专家,所以我可能是错的)。
代码是:
IL_001e: ldarg.0
IL_001f: ldfld !0[] class System.Collections.Generic.List`1<!T>::_items
IL_0024: ldarg.0
IL_0025: dup
IL_0026: ldfld int32 class System.Collections.Generic.List`1<!T>::_size
IL_002b: dup
IL_002c: stloc.0 // store the size pre incrementing
IL_002d: ldc.i4.1
IL_002e: add // do the increment
IL_002f: stfld int32 class System.Collections.Generic.List`1<!T>::_size
IL_0034: ldloc.0 // reload the stored size to use as index in stelem
IL_0035: ldarg.1
IL_0036: stelem.any !T
这到底是什么 __PostIncrement
?在VB中符号化后自增IL代码是SharpDevelop的发明吗?或者它实际上是我可以在自己的 VB 代码中使用的某种定义?
最佳答案
__PostIncrement 相当于 C# operator++
.这是一种增加(加一)数字的快速方法。不幸的是,根据list of operators in Visual Basic , 没有等价物。
关于vb.net - 什么是反编译的 VB 中的 __PostIncrement(通过 ILSpy),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14109545/