jeudi 20 février 2020

C# Switch If condition to expand the switch cases

I have some data which need to converted, for that I need a switch condition with more than 50 cases, I need the same cases 3 times but in the third time I need the 50 cases and some more and I don't want to write the same code twice. Maybe there is a possibility to do something like this.

switch (example)
{
    case "1":
        //do something
    case "2":
        //do something
    case "50":
        //do something
    //now maybe something like this
    if (condition == true)
    {
        case "1":
            //do something else than above at case "1", and so on 
            //now its i little bit illogical, but i neet to do the first 50 cases and then
            //use the cases 1 to 50 again but with other actions 
    }
}

Aucun commentaire:

Enregistrer un commentaire