Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simplify the code pls 1

Status
Not open for further replies.

peac3

Technical User
Jan 17, 2009
226
AU
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:

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 + ")"));
                        }
                    }
                }
 
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 + ")"));
}[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.
 
Take two on posting code...

Code:
[COLOR=#0000FF][/color][COLOR=#0000FF][highlight #FFFFFF]if[/color][COLOR=#000000] (CodeList[i].CODE_ACTV_F.IsEqual([/color][COLOR=#A31515]"Y"[/color][COLOR=#000000]) || (CodeList[i].BRANCH_CODE.Trim() == sitecode.Trim() && IsUpdateMode))
{
    KeyValuePairList.Add([/color][COLOR=#0000FF]new[/color][COLOR=#000000] [/color][COLOR=#2B91AF]KeyValuePair[/color][COLOR=#000000]<[/color][COLOR=#0000FF]string[/color][COLOR=#000000], [/color][COLOR=#0000FF]string[/color][COLOR=#000000]>(CodeList[i].BRANCH_CODE, CodeList[i].BRANCH_CODE + [/color][COLOR=#A31515]" - "[/color][COLOR=#000000] + CodeList[i].BRANCH_DESC + [/color][COLOR=#A31515]")"[/color][COLOR=#000000]));
}[/color][/highlight]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top