关于c++enum用法,enum用法这个问题很多朋友还不知道,今天小六来为大家解答以上的问题,现在让我们一起来看看吧!
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; }}。
本文分享完毕,希望对大家有所帮助。
标签:
免责声明:本文由用户上传,如有侵权请联系删除!