标签:blog http ar color sp on div log bs
1.枚举类型定义:
TYPE
days = (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday); //枚举类型,属于顺序类型,序号从0开始
colors =(red,yellow,blue,green,black); //可以同时多个枚举类型定义
//下面定义方法是错误的
days_e1 =(‘Sunday‘,‘Monday‘,‘Tuesday‘,‘Wednesday‘,‘Thursday‘,‘Friday‘,‘Saturday‘); //错误:枚举类型元素只能是标识符;
days_e2 =(1,2,3,4,5,6,7); //错误:枚举类型元素只能是标识符;
colors_e1=(red,yellow,white)//错误:枚举类型中元素不能和其他的元素相同;
2.类型类型可以用 顺数函数ord,pred,succ,low,high操作
3.枚举类型变量只能进行赋值运算和关系运算,不能进行算术运算和逻辑运算。
//合法性:
week := Sunday;
if week=Sunday then write(‘rest‘);
//不合法的:
Sunday := 1; //错把枚举值当成变量名;
days := blue; //枚举值blue不属于枚举变量weekday的值域;
read(color); //枚举类型变量 不能用读语句进行赋值;
write(week); writeln(blue);//不能通过写语句输出枚举类型的变量值和枚举值。
4.枚举类型应用:
temp:=StrToInt(Edit1.Text);
case temp of
0:week:=Sunday;
1:week:=Monday;
2:week:=Tuesday;
3:week:=Wednesday;
4:week:=Thursday;
5:week:=Friday;
6:week:=Saturday;
end;
枚举类型的定义和应用
标签:blog http ar color sp on div log bs
原文地址:http://www.cnblogs.com/delphiclub/p/4167957.html