如果DWORD的地图为int或uint? [英] Should DWORD map to int or uint?
问题描述
当翻译的Windows API(包括数据类型)为P / Invoke的,我应该替换DWORD与 INT
或 UINT
?
When translating the Windows API (including data types) into P/Invoke, should I replace DWORD with int
or uint
?
这是正常的无符号,但我看到人们使用 INT
随处可见,而不是(是CLS警告只是因为?的即使在.NET Framework本身做的这个),所以我从来没有真正知道哪一个是正确的使用。
It's normally unsigned, but I see people using int
everywhere instead (is it just because of the CLS warning? even the .NET Framework itself does this), and so I'm never really sure which one is the correct one to use.
推荐答案
好了的根据MSDN DWORD
是到4294967295范围为0无符号整数。
Well according to the MSDN DWORD
is an unsigned integer with a range of 0 to 4294967295.
所以,理想情况下,你应该用 UINT
替换,而不是 INT
。
So ideally you should replace it with uint
rather than int
.
然而,正如你已经发现 UINT
非CLS兼容,所以如果你的方法,你应该用公开的 INT
并做转换。该推论是,如果你的方法是不是你的程序集外使用,你应该将其标记为内部
,而不是公开
。然后,你就可以使用 UINT
。
However, as you have spotted uint
is non-CLS compliant so if your method is publicly visible you should use int
and do the conversion. The corollary to that is that if your method isn't used outside your assembly you should mark it as internal
rather than public
. Then you'll be able use a uint
.
这篇关于如果DWORD的地图为int或uint?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!