博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c#枚举类型_C枚举类型
阅读量:2506 次
发布时间:2019-05-11

本文共 1557 字,大约阅读时间需要 5 分钟。

c#枚举类型

Using the typedef and enum keywords we can define a type that can have either one value or another.

使用typedefenum关键字,我们可以定义一个可以具有一个值或另一个值的类型。

It’s one of the most important uses of the typedef keyword.

这是typedef关键字最重要的用途之一。

This is the syntax of an enumerated type:

这是枚举类型的语法:

typedef enum {  //...values} TYPENAME;

The enumerated type we create is usually, by convention, uppercase.

按照惯例,我们创建的枚举类型通常是大写的。

Here is a simple example:

这是一个简单的示例:

typedef enum {  true,  false} BOOLEAN;

C comes with a , so this example is not really practical, but you get the idea.

C带有 ,因此该示例并不实际,但您可以理解。

Another example is to define weekdays:

另一个示例是定义工作日:

typedef enum {  monday,    tuesday,  wednesday,  thursday,  friday,  saturday,  sunday} WEEKDAY;

Here’s a simple program that uses this enumerated type:

这是使用此枚举类型的简单程序:

#include 
typedef enum { monday, tuesday, wednesday, thursday, friday, saturday, sunday} WEEKDAY;int main(void) { WEEKDAY day = monday; if (day == monday) { printf("It's monday!"); } else { printf("It's not monday"); }}

Every item in the enum definition is paired to an integer, internally. So in this example monday is 0, tuesday is 1 and so on.

枚举定义中的每个项目都在内部与一个整数配对。 因此,在此示例中, monday为0, tuesday为1,依此类推。

This means the conditional could have been if (day == 0) instead of if (day == monday), but it’s way simpler for us humans to reason with names rather than numbers, so it’s a very convenient syntax.

这意味着条件可以是if (day == 0)而不是if (day == monday) ,但是对于我们人类来说,使用名称而不是数字来进行推理更简单,因此这是一种非常方便的语法。

翻译自:

c#枚举类型

转载地址:http://pamgb.baihongyu.com/

你可能感兴趣的文章
Java知识积累1-StringAlign实现文字居中左右对齐
查看>>
mxonline实战2, 后台管理神器xadmin
查看>>
mxonline实战6 , 忘记用户密码时进行重置
查看>>
[leedcode 142] Linked List Cycle II
查看>>
Cookie的使用
查看>>
DOM基础
查看>>
初学者应当掌握的算法
查看>>
React+webpack开发环境的搭建
查看>>
c#基础语言编程-程序集和反射
查看>>
手把手教你使用“谷歌云消息服务(GCM)"
查看>>
图解SQL inner join、left join、right join、full outer join、union、union all的区别
查看>>
生成日志
查看>>
WCF初探-19:WCF消息协定
查看>>
算法技巧之打表
查看>>
nodejs创建服务器
查看>>
安卓 图片加载框架ImageLoader
查看>>
ApplicationBar
查看>>
Spring Boot Docker 实战
查看>>
Div Vertical Menu ver3
查看>>
Git简明操作
查看>>