在C#中可以将Char强制转换为Int32产生负值吗? [英] In C# can casting a Char to Int32 produce a negative value?

查看:82
本文介绍了在C#中可以将Char强制转换为Int32产生负值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还是总是保证所有可能的字符都是正数?

Or is it always guaranteed to be positive for all possible Chars?

推荐答案

保证非负数。

char unsigned 16位值。

来自C#4规范的4.1.5节:

From section 4.1.5 of the C# 4 spec:


char 类型表示无符号16位整数,其值在0到65535之间。 char 类型的可能值集对应于Unicode字符集。尽管 char ushort 具有相同的表示形式,但并非一种类型允许的所有操作都允许另一种类型。

The char type represents unsigned 16-bit integers with values between 0 and 65535. The set of possible values for the char type corresponds to the Unicode character set. Although char has the same representation as ushort, not all operations permitted on one type are permitted on the other.

这篇关于在C#中可以将Char强制转换为Int32产生负值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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