IntPtr gets operators !!!

This seems so incredibly long overdue, but at last as of .NET 4, IntPtr has + and – operators added to it !!

This means you can now easily write code such as :

    Dim ptr As IntPtr

    . . . .
    ptr += 4


this is great when dealing with offsets etc.


The actual implementation is kind of interesting. Here I’m seeing  the implementation as :

Public Shared Operator (ByVal pointer As IntPtr, ByVal offset As Integer) As IntPtr
       Return New
End Function


I guess this is because it is the 32 bit version of the library. Hopefully in the 64 bit version it calls on IntPtr.ToInt64 😉

1 Comment so far

  1.   JaredPar on November 5th, 2009          

    Yes, in the 64 bit version of mscorlib it uses .ToInt64