C# sizeof object pointer (SAFE context)
Ok while sizeof(Myenum) and sizeof(int) works, I would like to use sizeof(object), but I don't want the size of the object, but the size of pointer... only for portability reason, I need to know if is a 64 bit pointer or 32 bit pointer, I can avoid using sizeof if is ok with conditional compilation, 开发者_如何学Gobut I don't know if there are constants to check if we are on a 32 bit system instead of 64 bit
Thanks for suggestions
Use IntPtr.Size
.
Reference : Simple way to check if you're on a 64-bit machine
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 is a pointer, found it at IntPtr Structure.
精彩评论