C# 等效于 C++ 中的 64 位 unsigned long long
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18851705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# equivalent of 64-bit unsigned long long in C++
提问by Gags
I am building a DLL which will be used by C++ using COM.
Please let me know what would be the C# equivalent of C++ 64-bit unsigned long long
.
我正在构建一个将由 C++ 使用 COM 使用的 DLL。请让我知道 C++ 64-bit 的 C# 等效项是什么unsigned long long
。
Will it be ulong type in C# ? Please confirm.
它会是 C# 中的 ulong 类型吗?请确认。
Thanks, Gagan
谢谢,加根
回答by Dzmitry Martavoi
回答by Ivan Ishchenko
Since C++11, you can use these:
从 C++11 开始,您可以使用这些:
int8_t
int16_t
int32_t
int64_t
uint8_t
uint16_t
uint32_t
uint64_t
int8_t
int16_t
int32_t
int64_t
uint8_t
uint16_t
uint32_t
uint64_t
Their size is guaranteed to remain the same regardless of anything.
无论发生什么,它们的大小都保证保持不变。
回答by HerpDerpington
For anything that goes beyond ulong
, you might as well use the C# BigInteger
Structure.
对于超出范围的任何内容ulong
,您不妨使用 C#BigInteger
结构。
回答by Davide Cannizzo
In C++, each integer type doubles its size when running on a 64-bit machine, rather than a 32-bit one.
Therefore, stating that C# int
or long
could be equivalent to C++ int
or long
is incorrect.
在 C++ 中,当在 64 位机器上运行时,每种整数类型的大小都会加倍,而不是在 32 位机器上运行。
因此,声明 C#int
或long
可能等同于 C++int
或long
不正确。
Rather, in C# there is a type called IntPtr
, which was exclusively made for P/Invoke. Indeed, this one changes its size from 4 bytes on a 32-bit machine to 8 bytes on a 64-bit machine, and so this is the correct equivalent of the C++ unsigned long
or Windows ULONG
.
相反,在 C# 中有一个名为 的类型IntPtr
,它专为 P/Invoke 制作。事实上,这将它的大小从 32 位机器上的 4 个字节更改为 64 位机器上的 8 个字节,因此这是 C++unsigned long
或 Windows的正确等价物ULONG
。