到底什么是一个IntPtr是什么呢?

问题描述:

通过使用智能感知,看着别人的code,我也碰到过这种的IntPtr 输入;要使用的每一个它需要的时候我已经简单地把 IntPtr.Zero ,发现大多数功能工作。它究竟是什么,当/为什么使用它?

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?

这是一个本机(特定于平台)大小的整数。它的内部重新psented为 $ P $无效* ,但公开为整数。每当你需要存储一个非托管指针,不想使用不安全 code您可以使用它。 IntPtr.Zero 是有效 NULL (一个空指针)。

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