C/C++只支持整型值(用字符常量也可以,但编译器事实上也是把字符常量量转化成了整型值的).
其实:
C/C++支持 int 和char,switch语句中的case只能是常量.是整型,字符或枚举三种.
C#支持int、char、string。
Enum其实也就是int……
From MSDN:
In ANSI C, the expressions that define the value of an enumerator constant always have int type; thus, the storage associated with an enumeration variable is the storage required for a single int value. An enumeration constant or a value of enumerated type can be used anywhere the C language permits an integer expression.
____________________________________________________________
From MSDN:
switch (expression)
{
case constant-expression:
statement
jump-statement
[default:
statement
jump-statement]
}
C++
The expression must be of an integral type or of a class type for which there is an unambiguous conversion to integral type.
(参考地址:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pluslang_The_C.2b2b_.switch_Statement.asp)
C#
expression
An integral or string type expression.
(参考地址:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfTheSwitchStatement.asp)
___________________________________________________________________
参见CSDN 的帖子:
http://community.csdn.net/Expert/topic/3857/3857598.xml?temp=.1475489