为什么不能算一个无符号整数? [英] Why is Count not an unsigned integer?

查看:105
本文介绍了为什么不能算一个无符号整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能显示的文件:
  <一href="http://stackoverflow.com/questions/782629/why-does-net-use-int-instead-of-uint-in-certain-classes">Why确实.NET使用int,而不是UINT在某些类别?
  为什么Array.Length一个int,而不是一个UINT

Possible Duplicates:
Why does .NET use int instead of uint in certain classes?
Why is Array.Length an int, and not an 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:

<一个href="http://msdn.microsoft.com/en-us/library/bhc3fa7f.aspx">http://msdn.microsoft.com/en-us/library/bhc3fa7f.aspx

这篇关于为什么不能算一个无符号整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆