您当前所在的位置: 首页 > 体检 > > 正文

快资讯丨c语言枚举类型enum用法_enum用法

日期:2023-06-27 03:47:07 来源:互联网
分享到:


(资料图片)

1、下面是一个例举的例子:public enum WeekDay { SUN(1, "Sunday", "SUN"), MON(2, "Monday", "MON"), TUE(3, "Tuesday", "TUE"), WED(4, "Wednesday", "WED"), THU(5, "Thursday", "THU"), FRI(6, "Friday", "FRI"), SAT(7, "Saturday", "SAT"); private String shortName; private String fullName; private int dayOfWeek; private WeekDay(int dayOfWeek, String name, String sname) { this.dayOfWeek = dayOfWeek; fullName = name; shortName = sname; } public static WeekDay getDay(int dayIndex) { switch (dayIndex) { case 1: return SUN; case 2: return MON; case 3: return TUE; case 4: return WED; case 5: return THU; case 6: return FRI; case 7: return SAT; } return null; } public String getShortName() { return shortName; } public int getDayOfWeek() { return dayOfWeek; } @Override public String toString() { return fullName; }}。

本文就为大家分享到这里,希望小伙伴们会喜欢。

关键词:
x 广告
x 广告

Copyright   2015-2022 起点健康网版权所有   备案号:皖ICP备2022009963号-12   联系邮箱: 39 60 29 14 2@qq.com