Traverse all switch branches without goto I'm wondering wether there is a way to walk through every branch of this switch without using goto

    public static List&lt;KpiGroup&gt; GetKpiGroups(int siteId, int topLevelProjectId, SiteDetailsModel.KpiCategory category, bool applyMapFilters)
    {
        var kpiGroups = new List&lt;KpiGroup&gt;();

        switch (category)
        {
            case SiteDetailsModel.KpiCategory.Any:
            case SiteDetailsModel.KpiCategory.Wbs:
                kpiGroups.Add(KPIGetActiveSite(siteId, topLevelProjectId));
                if (category == SiteDetailsModel.KpiCategory.Any)
                    goto task;
                break;

            case SiteDetailsModel.KpiCategory.Task:
        task:
                kpiGroups.Add(KPIGetTicketStatus(siteId, topLevelProjectId));
                kpiGroups.Add(KPIGetTicketSeverityClosed(siteId, topLevelProjectId));
                kpiGroups.Add(KPIGetTicketSeverityOpen(siteId, topLevelProjectId));
                kpiGroups.Add(KPIGetTicketOwnerOpen(siteId, topLevelProjectId));
                kpiGroups.Add(KPIGetTicketOwnerClosed(siteId, topLevelProjectId));
                kpiGroups.Add(KPIGetTicketActivity(siteId, topLevelProjectId));
                if (category == SiteDetailsModel.KpiCategory.Any)
                    goto sysConfig;
                break;

            case SiteDetailsModel.KpiCategory.SysConfig:
        sysConfig:
                kpiGroups.Add(KPIGetSysConfigOverview(siteId, topLevelProjectId));
                kpiGroups.Add(KPIGetSysConfigDeviceTypes(siteId, topLevelProjectId));
                kpiGroups.Add(KPIGetSysConfigLevel(siteId, topLevelProjectId));
                break;

            default:
                throw new ArgumentOutOfRangeException(String.Format("GetKpiGroups {0}", category.ToString()));
        }

        return kpiGroups;
    }
As Dan Lyons stated in his comment you could use the goto case ... instead of custom goto labels. Check the example on the link he provided.

If you want to avoid using goto completely. I suggest you take the adding of the items out of the switch/case and place that in methods. And then, in every case you call the appropriate method to add the necessary items. Example:

List&lt;KpiGroup&gt; kpiGroups = new List&lt;KpiGroup&gt;();

public static List&lt;KpiGroup&gt; GetKpiGroups(int siteId, int topLevelProjectId, SiteDetailsModel.KpiCategory category, bool applyMapFilters)
{
    switch (category)
    {
        case SiteDetailsModel.KpiCategory.Wbs: AddWbsGroups(); break;
        case SiteDetailsModel.KpiCategory.Task: AddTaskGroups(); break;
        case SiteDetailsModel.KpiCategory.SysConfig: AddSysConfigGroups(); break;
        case SiteDetailsModel.KpiCategory.Any:
            AddWbsGroups();
            AddTaskGroups();
            AddSysConfigGroups();
            break;
        default:
            throw new ArgumentOutOfRangeException(String.Format("GetKpiGroups {0}", category.ToString()));
    }

    return kpiGroups;
}

public void AddWbsGroups(int siteId, int topLevelProjectId)
{
    kpiGroups.Add(KPIGetActiveSite(siteId, topLevelProjectId));
}

public void AddTaskGroups(int siteId, int topLevelProjectId)
{
    kpiGroups.Add(KPIGetTicketStatus(siteId, topLevelProjectId));
    kpiGroups.Add(KPIGetTicketSeverityClosed(siteId, topLevelProjectId));
    kpiGroups.Add(KPIGetTicketSeverityOpen(siteId, topLevelProjectId));
    kpiGroups.Add(KPIGetTicketOwnerOpen(siteId, topLevelProjectId));
    kpiGroups.Add(KPIGetTicketOwnerClosed(siteId, topLevelProjectId));
    kpiGroups.Add(KPIGetTicketActivity(siteId, topLevelProjectId));
    kpiGroups.Add(KPIGetActiveSite(siteId, topLevelProjectId));
}

public void AddSysConfigGroups(int siteId, int topLevelProjectId)
{
    kpiGroups.Add(KPIGetSysConfigOverview(siteId, topLevelProjectId));
    kpiGroups.Add(KPIGetSysConfigDeviceTypes(siteId, topLevelProjectId));
    kpiGroups.Add(KPIGetSysConfigLevel(siteId, topLevelProjectId));
}


It looks like overkill using the methods but your code still looks clean, readable and maintainable. It's up to you, use this method or the suggestion from Dan Lyons.