×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

simplify the code pls

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:

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

[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.

RE: simplify the code pls

Take two on posting code...

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

(OP)
Thanks Moregelen

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close