C# - Effeciently writing code -
i pasting code snippet below. body suggest better , effecient way of writing this. minimum code written , avoid repetition.
private void setcontrolvisibility() { if (dropdownlist1.selecteditem.text.equals("getassetsbasicbyid") || dropdownlist1.selecteditem.text.equals("getassetdetailsbyids")) { label2.text = "(please enter asset ids e.g. 1,2)"; chkexcludemapfunds.visible = false; chkpublishxml.visible = true; } else if (dropdownlist1.selecteditem.text.equals("getassetsbasicbysedols") || dropdownlist1.selecteditem.text.equals("getassetdetailsbysedols")) { label2.text = "(please enter sedols e.g. b1yw440,0003496)"; chkexcludemapfunds.visible = false; chkpublishxml.visible = true; } else if (dropdownlist1.selecteditem.text.equals("getinvestmentreportbyids")) { label2.text = "(please enter asset ids e.g. 1:100)"; chkexcludemapfunds.visible = true; chkpublishxml.visible = false; } else if (dropdownlist1.selecteditem.text.equals("getinvestmentreportbysedol")) { label2.text = "(please enter sedols e.g. b1yw440:100)"; chkexcludemapfunds.visible = true; chkpublishxml.visible = false; } }
my alternate code:
private void setcontrolvisibility() { string resulttext; bool b = false; switch (dropdownlist1.selecteditem.text) { case "getassetsbasicbyid": case "getassetdetailsbyids": b = true; resulttext = "(please enter asset ids e.g. 1,2)"; break; case "getassetsbasicbysedols": case "getassetdetailsbysedols": b = true; resulttext = "(please enter sedols e.g. b1yw440,0003496)"; break; case "getinvestmentreportbyids": resulttext = "(please enter asset ids e.g. 1:100)"; break; case "getinvestmentreportbysedol": resulttext = "(please enter sedols e.g. b1yw440:100)"; break; default: return; } chkexcludemapfunds.visible = !b; chkpublishxml.visible = b; label2.text = resulttext; }
Comments
Post a Comment