What is the best alternative for a if --else if --block that contains many if statements.
code:
string word="";
if(letter=='a')
{
// do some action
call(a);
}
else if (letter=='b')
{
call(b)
}
else if (letter=='c')
{
call(c)
}
else if (letter=='d')
{
// do some action
call(d)
}
else if (letter=='e')
{
// do some action
call(e)
}
................
..............
else if (letter=='z')
{
// do some action
call(z)
}
If there are many if-else statements what is the best way to find a solution for such a scenario. Is there a way to effectively design such a scenario using classes/objects?
I am sure many of us would have faced such problems like this during design/coding. Is there a effective way to handle such a situation?
NO SWITCH STATEMENTS PLEASE. AN EFFECTIVE DESIGN ALGORITHM USING C# OBJECTS WOULD BE THE BEST BET.
Aucun commentaire:
Enregistrer un commentaire