Add offset to IntPtr

前端 未结 7 1301
庸人自扰
庸人自扰 2020-11-30 06:59

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 I

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 07:59

    I suggest you to use ToInt64() and long to perform your computation. This way you will avoid problem on 64 bits version of the .NET framework.

    IntPtr ptr = new IntPtr(oldptr.ToInt64() + 2);
    

    This add a bit of overhead on 32 bits system, but it is safer.

提交回复
热议问题