mardi 6 mars 2018

alternative to else if for random number C#.net

Is there a shorter way to check my random number from 1 - 100 (catNum) against this table of animals? This one doesn't look so bad but I have several more larger tables to work through, I would like to use less lines than I would have to using the method below:

if (catNum < 36) { category = "Urban"; }
        else if (catNum < 51) { category = "Rural"; }
        else if (catNum < 76) { category = "Wild"; }
        else if (catNum < 86) { category = "Wild Birds"; }
        else { category = "Zoo"; }

example of larger tables

Aucun commentaire:

Enregistrer un commentaire