为什么 .NET Framework 不使用无符号数据类型? [英] Why does .NET Framework not use unsigned data types?

查看:32
本文介绍了为什么 .NET Framework 不使用无符号数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
为什么 Array.Length 是 int 而不是 uint

.NET Framework 不使用无符号数据类型背后是否有原因?

Is there is a reason behind it .NET Framework not using unsigned data types?

我不应该在我的代码中采用它们,但例如,List<> 的 Count 属性是一个 int.你不能有一个负数,那么为什么不应该把它定义为一个 uint 呢?即使我知道计数不能为负数,我也应该只使用 int 吗?

Shouldn't I be adopting them in my code, but for example, the Count property of a List<> is an int. You can't have a negative count, so why shouldn't it be defined as a uint? Should I use only int's even though I know the count can not be negative?

推荐答案

无符号数字类型不是 CLS 兼容,因此它们不应用于任何 API - 特别是 .NET 框架.

Unsigned numeric types are not CLS compliant so they should not be used for any API - especially the .NET framework.

基本上,符合 CLS 的代码仅使用在所有 .NET 语言中都可用的类型.某些语言(如 VB.NET)不支持无符号数字类型.

Basically, CLS compliant code only utilizes types that are available in all .NET languages. Some languages (like VB.NET) does not support unsigned numeric types.

这篇关于为什么 .NET Framework 不使用无符号数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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