Question

I was just perusing the decompiled code for System.Collections.Generic.List(Of T).Add(item As T) using ILSpy and I found a call to __PostIncrement. I've never heard of such a thing in VB, so I did some digging and found:

  1. In VB, the code is Me._items(__PostIncrement(Me._size)) = item.
  2. In C#, the code is this._items[this._size++] = item; using the actual post-increment operator in that language
  3. In MSIL, there is not a function call. It appears to work like a C# post-increment would (the comments are mine, but I'm no expert at MSIL,so I could be wrong).

The code is:

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

What exactly is this __PostIncrement? Is it a SharpDevelop invention to symbolize post-increment IL code in VB? Or is it actually some kind of definition I could use in my own VB code?

Was it helpful?

Solution

__PostIncrement is the equivalent of the C# operator++. It is a quick way to increment (add one) to a number. Unfortunately, according to the list of operators in Visual Basic, there is no equivalent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top