I didn't understand what is IntPtr, could someone explain this? thanks
-
1Also see: [Just what is an IntPtr exactly?](http://stackoverflow.com/questions/1148177/just-what-is-an-intptr-exactly). – Cody Gray - on strike Feb 05 '11 at 09:54
6 Answers
It is an integer that is the same size as a pointer. 32 bits wide in 32 bit images, 64 wide in 64 bit images.

- 601,492
- 42
- 1,072
- 1,490
It is the managed counterpart of void*
.
You can cast to and from void*
for usage in managed code without having to resort to unsafe code in managed layers, eg C#.

- 115,091
- 17
- 196
- 297
It's a .NET platform-specific type that is used to represent a pointer or a handle.
The IntPtr type is designed to be an integer whose size is platform-specific. That is, an instance of this type is expected to be 32-bits on 32-bit hardware and operating systems, and 64-bits on 64-bit hardware and operating systems.
The IntPtr type can be used by languages that support pointers, and as a common means of referring to data between languages that do and do not support pointers.
IntPtr objects can also be used to hold handles. For example, instances of IntPtr are used extensively in the System.IO.FileStream class to hold file handles.
(from MSDSN)

- 126,886
- 32
- 213
- 327
This is about the c and c++ type intptr_t but the principle is the same. What is uintptr_t data type
-
At least pretend to answer the question by copying and pasting the relevant information from the docs. A link is not sufficient to qualify as an answer. – Cody Gray - on strike Feb 05 '11 at 09:52
-
I wanted to show author how trivial is finding answer to such a question. – Xorty Feb 05 '11 at 17:18
-
Well, the answers from people here are a lot more clear then the msdn which i have tried to read before i put the question. Thanks for the effort and good will anyway. – lital maatuk Feb 05 '11 at 18:01
A pointer sized blackbox. Sometimes you have languages that don't support unsafe code/pointers, and thus need to use IntPtr in the API.
I think its use has been reduced since .net 2 since many of its use-cases are better fit for safe-handles.

- 106,488
- 23
- 218
- 262