I have this lines in C# Visual Studio 2010:
IntPtr a = new IntPtr(10);
IntPtr b = a + 10;
And it says:
Operator '+' cannot be applied to operands of type 'System.IntPtr' and 'int'.
MSDN says that this operation should work.
If you are targetting .net 4 then your code will work.
For earlier versions you need to use IntPtr.ToInt64
.
IntPtr a = new IntPtr(10);
IntPtr b = new IntPtr(a.ToInt64()+10);
Use ToInt64
rather than ToInt32
so that your code works for both 32 and 64 bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With