char类型在C#中尺寸 [英] size of char type in c#

查看:598
本文介绍了char类型在C#中尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道为什么我们的字符类型的大小= 2个字节在C#(。网)不同于1字节在其他编程语言?

Just wondering why do we have 'char' type of size=2Bytes in c#(.net) unlike 1Byte in other programming languages?

推荐答案

一个字符是单向code在C#中,因此可能的字符数超过255。所以,你需要两个字节。

A char is unicode in C#, therefore the number of possible characters exceeds 255. So you'll need two bytes.

扩展ASCII例如有255个字符集,因此可以存​​储在一个单个字节。这也是在 System.Encoding 命名空间的整体目标,为不同的系统可以有不同的字符集和字符大小。因此,C#可以处理一/四/等。烧焦个字节,但是统一code UTF-16为默认值。

Extended ASCII for example has a 255-char set, and can therefore be stored in one single byte. That's also the whole purpose of the System.Encoding namespace, as different systems can have different charsets, and char sizes. C# can therefore handle one/four/etc. char bytes, but Unicode UTF-16 is default.

这篇关于char类型在C#中尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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