Does CC ++C # support string Switch-case? ?

xiaoxiao2021-03-06  15

C / C only supports integer values ​​(can also be used as a constant, but the compiler is actually converting the character constant amount into an integer value).

in fact:

C / C supports INT and CHAR, CASE in the switch statement can only be constant. It is integer, characters or enumeration. C # support int, char, string.

ENUM is actually 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 TYPEER OF A Class Type for Which There Is An Unambiguous Conversion To Integral Type. (Reference Address: 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. (Reference address: http://msdn.microsoft.com/library/default.asp? URL = / library / en-us / csref / html / vclrftheswitchStatement.asp)

________________________________________________________

See 9CBS posts:

http://community.9cbs.net/expert/topic/3857/3857598.xml?temp=.1475489

转载请注明原文地址:https://www.9cbs.com/read-45923.html

New Post(0)