IntPtr gets operators !!!
Posted
Thu, Nov 5 2009 11:48
by
bill
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 IntPtr((pointer.ToInt32 - offset))
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 ;)