我有一个枚举类型:
enum Day {sunday, monday, tuesday...}
和变量:
Day day = Day.sunday;
我希望能够增加这一天。像这样的东西:
day++; // this would be wonderful
day = Day.getByIndex(day.index + 1); // something like this can also work
但我找不到这样的东西。是所有日子都使用开关的唯一选择吗?
答案 0 :(得分:3)
enum Day {sunday, monday, tuesday}
void main() {
var day = Day.sunday;
print(day);
print(Day.values[day.index + 1]);
}
众所周知,Dart枚举不是很强大。我猜他们最终会得到一些改革。