Just what is an IntPtr exactly?

Callum Rogers picture Callum Rogers · Jul 18, 2009 · Viewed 124.2k times · Source

Through using IntelliSense and looking at other people's code, I have come across this IntPtr type; every time it has needed to be used I have simply put null or IntPtr.Zero and found most functions to work. What exactly is it and when/why is it used?

Answer

Sam Harwell picture Sam Harwell · Jul 18, 2009

It's a "native (platform-specific) size integer." It's internally represented as void* but exposed as an integer. You can use it whenever you need to store an unmanaged pointer and don't want to use unsafe code. IntPtr.Zero is effectively NULL (a null pointer).