C# IntPtr Conversion Guide

In C#, you can retrieve values using IntPtr in the following way:

  1. Convert the IntPtr value to a 32-bit signed integer using the ToInt32 method.
IntPtr ptr = new IntPtr(123);
int value = ptr.ToInt32();
  1. Convert the IntPtr value to a 64-bit signed integer using the ToInt64 method.
IntPtr ptr = new IntPtr(123);
long value = ptr.ToInt64();
  1. Convert an IntPtr value to a pointer type using the ToPointer method.
IntPtr ptr = new IntPtr(123);
int* value = (int*)ptr.ToPointer();

Caution is necessary when using the ToPointer method, as it may result in unsafe code after converting to a pointer type. Exercise caution when handling it.

bannerAds