Say you have a function that returns an enum:
public enum ServerStatus
{
Down,
Up
}
private ServerStatus GetServerStatus(int time)
{
if (time >= 0 && time < 12)
{
return ServerStatus.Down;
}
else if (time >= 12 && time <= 23)
{
return ServerStatus.Up;
}
else
{
return ?? // Server status is neither Up nor Down
}
}
Should I:
- Add “Neither” to ServerStatus
- Makes GetServerStatus return ServerStatus? and return null
- Return a another bool that indicate if the value is meaningful
If that case should never happen in practice, and you don’t expect to have to produce something other than ‘Up’ and ‘Down’, then you should throw an exception.