Search code snippets, questions, articles...

Switch with connected cases

Switch with multiple connected cases with the same return value
switch (this) {
    case WeatherState.clear:
        return WeatherCondition.clear;
    case WeatherState.snow:
    case WeatherState.sleet:
    case WeatherState.hail:
        return WeatherCondition.snowy;
    case WeatherState.thunderstorm:
    case WeatherState.heavyRain:
    case WeatherState.lightRain:
    case WeatherState.showers:
        return WeatherCondition.rainy;
    case WeatherState.heavyCloud:
    case WeatherState.lightCloud:
        return WeatherCondition.cloudy;
    default:
        return WeatherCondition.unknown;
}
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

Search Index Data (The code snippet can also be found with below search text)

switch
case
multiple
Was this helpful?
0 Comments