I'm looking for a way to perform pointer operations in C# or .NET in particular.
I want to do something very simple
Having a pointer IntPtr I want to get IntPtr object which points to 2 bytes ahead.
I read some post that the foolowing snippet will work...
IntPtr ptr = new IntPtr(oldptr.ToInt32() + 2);
But I have doubts whether this statement is also valid for 64-bit machine (since addressing is in 64-bits there)..
I found this elegant method to add offset, but unfortunately is in .NET 4.0 only http://msdn.microsoft.com/en-us/library/system.intptr.add%28VS.100%29.aspx
In .net 4 static Add() and Subtract() methods have been added.
IntPtr ptr = IntPtr.Add(oldPtr, 2);
http://msdn.microsoft.com/en-us/library/system.intptr.add.aspx