我只是在仔细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 代码中使用的某种定义?