.net - Nested If Else statement in C# -


i have nested if else statement checks enum states

if ( status == enum.value1)  {     //call function 1  } else if ( status == enum.value2)  {     //call function 2 } else if ( status == enum.valu3 )  {    call function 3.  } else if ( status == enum.valu3  || status == enum.valu10)  {    call function 4.  } 

how refactor/simplify this? not want use swicth case.

try dictionary. fill delegates:

dictionary<yourenum, action> dict = new dictionary<yourenum, action>(); dict.add(yourenum.value1, mymethod1); dict.add(yourenum.value2, mymethod2); //etc. 

and return them plus invoke them when needed:

dict[myenumvalue](); 

Comments