0

I have this enum

    public enum ActionStatus
    {
        WINDUP, ACTIVE, COOLDOWN, DONE
    }

and this property

    public int TicksUntilNextStatus => Status switch
    {
        ActionStatus.WINDUP => WindupEnd - CurrentTime,
        ActionStatus.ACTIVE => ActiveEnd - CurrentTime,
        ActionStatus.COOLDOWN => CooldownEnd - CurrentTime,
        ActionStatus.DONE => 0
    };

Status is declared as public ActionStatus Status { get => ... }

the compiler issues a warning that the switch is not exhaustive. Why?

user973223
  • 127
  • 1
  • 8
  • 3
    [This question](https://stackoverflow.com/questions/1098644/switch-statement-without-default-when-dealing-with-enumerations) and its responses may inspire you. Look at the second response in particular. – Bob Kaufman Apr 20 '20 at 01:42
  • 1
    Another thing to consider from the above link, what if you're not the owner of `ActionStatus`, and one day `ActionStatus` adds a new value `NOTACTIVE`. A default case needs to be added to circumvent this scenario, which can be done using the _ operator. – Hayden Apr 20 '20 at 01:47

0 Answers0