为什么我们不能有"焦炭"枚举类型 [英] Why we can't have "char" enum types

查看:145
本文介绍了为什么我们不能有"焦炭"枚举类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么我们不能有炭为基本枚举类型。
因为我们有一个字节,为sbyte,INT,UINT,长,ULONG,总之,USHORT为标的
枚举类型。
二是什么是一个枚举的默认基础类型?

I want to know why we can't have "char" as underlying enum type. As we have byte,sbyte,int,uint,long,ulong,short,ushort as underlying enum type. Second what is the default underlying type of an enum?

推荐答案

默认类型为int。在MSDN上的C#参考的更多信息。您也可以找到一个链接到MSDN上的 C#语言规范。我认为限制的原因可能是从语言规范,这些语句派生,第4.1.5节。

The default type is int. More information at the C# reference at MSDN. You can also find a link to the C# language specification at MSDN. I think the reason for the restriction probably derives from these statements in the language specification, section 4.1.5.

char类型被归类为一个
  整体式的,但它从不同
  其他整型有两种方式:

The char type is classified as an integral type, but it differs from the other integral types in two ways:

•有没有隐式转换
  与其他类型char类型。在
  特别是,即使为sbyte,
  字节和ushort类型具有的范围
  这完全值重新presentable
  使用char类型,隐
  从转换为sbyte,字节或
  USHORT到char是不存在的。

• There are no implicit conversions from other types to the char type. In particular, even though the sbyte, byte, and ushort types have ranges of values that are fully representable using the char type, implicit conversions from sbyte, byte, or ushort to char do not exist.

•char类型的常量必须是
  写成字符文字或
  整数文字结合有
  转换为char类型。例如,
  (char)10与相同与'\\ x000A'。

• Constants of the char type must be written as character-literals or as integer-literals in combination with a cast to type char. For example, (char)10 is the same as '\x000A'.

这篇关于为什么我们不能有"焦炭"枚举类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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