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?
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).