Add offset to IntPtr

前端 未结 7 1302
庸人自扰
庸人自扰 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条回答
  •  情书的邮戳
    2020-11-30 07:57

    You can use a extension method:

    public static IntPtrExtensions {
        public static IntPtr Add( this IntPtr ptr, int offSet ) {
            IntPtr ret = new IntPtr( ptr.ToInt64() + offSet );
            return ret;
        }
    }
    // ... somewhere else ...
    IntPtr pointer = GetHandle().Add( 15 );
    

提交回复
热议问题