问题描述
可能显示的文件:
Why确实.NET使用int,而不是UINT在某些类别?
为什么Array.Length一个int,而不是一个UINT
您好,
我一直想知道为什么Count是不是一个无符号整数,而不是一个签名呢?
I always wonder why Count isn't an unsigned integer instead of a signed one?
例如,采取ListView.SelectedItems.Count。元素的数量不能小于0,那么,为什么它是一个符号int?
For example, take ListView.SelectedItems.Count. The number of elements can't be less then 0, so why is it a signed int?
如果我尝试测试,如果有选择的元素,我想测试
If I try to test if there are elements selected, I would like to test
if (ListView.SelectedItems.Count == 0) {}
但因为它是一个符号整数,我一定要考
but because it's a signed integer, I have to test
if (ListView.SelectedItems.Count <= 0) {}
或者是有当.Count之间可能会与其中的任何情况; 0?
or is there any case when .Count could be < 0 ?
推荐答案
无符号整型是不符合CLS(的)
Unsigned integer is not CLS-compliant (Common Language Specification)
有关CLS更多信息兼容的code,看到此链接:
For more info on CLS compliant code, see this link:
http://msdn.microsoft.com/en-us/library/bhc3fa7f.aspx
这篇关于为什么不能算一个无符号整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!