博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Int8 and UInt8 types different from Byte and SByte
阅读量:6688 次
发布时间:2019-06-25

本文共 1515 字,大约阅读时间需要 5 分钟。

question:Why not to have a Int8 and UInt8 types instead of Byte and SByte in .Net framework

You mean SByte and Byte. Int8 would be signed SByte, UInt8 would be unsigned

Byte.
This also highlights the problem: some languages (notably VB.NET) have no
support for unsigned integers (they're not CLS-compliant). On the other
hand, they do all support Byte. Conversely, they don't have to support SByte
(and, predictably, VB.NET doesn't support it). This is one mismatch that
justifies a different type name: integers are mostly signed, bytes are
mostly unsigned, and language support reflects this.
Although you're technically right that a byte is an unsigned 8-bit integer,
it's rarely considered that way, and a signed 8-bit integer is even less
obvious. For example, you don't often perform arithmetic on bytes -- you
copy them around and manipulate their bits. This is another reason why it's
Byte and not UInt8.
Finally, Java started the tradition with byte, and it's no secret that the
CLR was heavily inspired by the JVM. The difference is that .NET actually
got it right by making "byte" unsigned. Java went for a foolish consistency,
eliminated unsigned types altogether, and made programmers' lives miserable
everywhere by forcing them to deal with signed bytes (which complicate code
for the vast majority of cases).
Of course, I didn't work on the CLR, so this is just my justification. I'd
repeat the decision if I were designing the type system.

转载于:https://www.cnblogs.com/pengyingh/articles/2478065.html

你可能感兴趣的文章
ionic3项目实战教程 - 第10讲 ionic3分类菜单设计(类似外卖)
查看>>
深度解析 | K8S API Server之入门须知
查看>>
LeanEngine 中使用 WebSocket
查看>>
浅入分析和Linux内核相关的文件夹/proc和/sys .
查看>>
Java 二分查找
查看>>
刚刚,阿里开源了一项重磅炸弹,终结程序员“中年危机”!
查看>>
《Spring Boot开发:从0到1》图片
查看>>
教你十分钟构建好 SpringBoot + SSM 框架
查看>>
吸烟场景运营商“烟客”获2000万元Pre-A轮融资,用于线下吸烟空间建设
查看>>
未来 Docker 的安全
查看>>
基于Android ActionBar的SearchView实时搜索结果
查看>>
spring boot +RabbitMQ +InfluxDB+Grafara监控实践
查看>>
马斯克的另一番“威胁论”:人类将成为人工智能的“宠物”
查看>>
Python 正则表达式(字符)详解
查看>>
Kali Linux 网络扫描秘籍 第三章 端口扫描(一)
查看>>
共享单车步入物联网军备战
查看>>
PHP 魔术变量
查看>>
推荐的PHP编码规范
查看>>
Gartner报告:东方金信进入Hadoop世界厂商名录
查看>>
Python_(1)数据类型及其常见使用方法(图文)
查看>>