lundi 7 septembre 2015

Whats a better thing to use, when using long else if - C#

What would be a good way, to refacor this code, to avoid the long nested else if statement? It goes quite longere, so could be nice to run it into a simple function. Any Ideas?

                    if (data == "Januar")
                    {
                        int cellnr = 1;
                        searchdata(row["CarNo"].ToString(), cellnr);
                    }
                    else if (data == "Februar")
                    {
                        int cellnr = 2;
                        searchdata(row["CarNo"].ToString(), cellnr);
                   }
                    else if (data == "Marts")
                    {
                        int cellnr = 3;
                        searchdata(row["CarNo"].ToString(), cellnr);
                    }
                    else if (data == "April")
                    {
                        int cellnr = 4;
                        searchdata(row["CarNo"].ToString(), cellnr);
                    }
                    else if (data == "Marts")
                    {
                        int cellnr = 5;
                        searchdata(row["CarNo"].ToString(), cellnr);
                    }

Regards Matias

Aucun commentaire:

Enregistrer un commentaire