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

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

问题描述

可能重复:
  为什么Array.Length一个int,而不是一个UINT

有是.NET框架不使用无符号的数据类型的背后原因是什么?

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

我不应该采取他们在我的code,但举例来说,一个名单,其中的计数的财产;>是一个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 code只利用了在所有.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框架不使用无符号的数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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