simplify the code pls
simplify the code pls
(OP)
Hi guys,
The codes below are working but I don't it's the best efficient code as they are some repetitive code and I haven't figured out what the best the way to simplify it.
Appreciate your help on this codes below:
The codes below are working but I don't it's the best efficient code as they are some repetitive code and I haven't figured out what the best the way to simplify it.
Appreciate your help on this codes below:
CODE
for (int i = 0; i < CodeList.Count; i++) { if (!IsUpdateMode) { if (CodeList[i].CODE_ACTV_F.IsEqual("Y")) { KeyValuePairList.Add(new KeyValuePair<string, string>(CodeList[i].BRANCH_CODE, CodeList[i].BRANCH_CODE + " - " + CodeList[i].BRANCH_DESC + ")")); } } else { if (CodeList[i].CODE_ACTV_F.IsEqual("Y") || CodeList[i].BRANCH_CODE.Trim() == sitecode.Trim()) { KeyValuePairList.Add(new KeyValuePair<string, string>(CodeList[i].BRANCH_CODE, CodeList[i].BRANCH_CODE + " - " + CodeList[i].BRANCH_DESC + ")")); } } }
RE: simplify the code pls
{
KeyValuePairList.Add(new KeyValuePair<string, string>(CodeList[i].BRANCH_CODE, CodeList[i].BRANCH_CODE + " - " + CodeList[i].BRANCH_DESC + ")"));
}[code]
That evaluates exactly the same way..
The only time CodeList[i].BRANCH_CODE.Trim() == sitecode.Trim() is only ever evaluated if IsUpdateMode is true and CodeList[i].CODE_ACTV_F.IsEquals("Y") is false... so this should do the same thing.
RE: simplify the code pls
CODE
if (CodeList[i].CODE_ACTV_F.IsEqual("Y") || (CodeList[i].BRANCH_CODE.Trim() == sitecode.Trim() && IsUpdateMode)) { KeyValuePairList.Add(new KeyValuePair<string, string>(CodeList[i].BRANCH_CODE, CodeList[i].BRANCH_CODE + " - " + CodeList[i].BRANCH_DESC + ")")); }
RE: simplify the code pls