问题
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, but 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
回答1:
Use IntPtr.Size
.
Reference : Simple way to check if you're on a 64-bit machine
回答2:
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.
来源:https://stackoverflow.com/questions/4416415/c-sharp-sizeof-object-pointer-safe-context