JDay2
asked on
if else statement in c#
I have the following if statement but need to add else when the case 12,15,18,22 is not I only need to show the OutTracking and InTracking currently now it shows nothing if I have other than case 12,15,18,22. I need to show without a hyperlink and plain text
[Rule("r100")]
public void r100Implementation(string OutTracking, string OutTrackingAlias, string InTracking, string InTrackingAlias)
{
if (OutTracking != null)
switch (OutTracking.Length)
{
case 12:
case 15:
case 22:
// fedex
UpdateFieldValue("OutTrackingAlias", "<a href=\"https://www.fedex.com/fedextrack/?cntry_code=us&tab=1&tracknums="
+ OutTracking
+ "&clienttype=dotcom\" target='_blank'>"
+ OutTracking
+ "</a>");
break;
case 18:
// UPS
UpdateFieldValue("OutTrackingAlias", "<a href=\"http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_US&InquiryNumber1="
+ OutTracking
+ "&clienttype=dotcom\" target='_blank'>"
+ OutTracking
+ "</a>");
break;
}
if (InTracking != null)
switch (InTracking.Length)
{
case 12:
case 15:
case 22:
// fedex
UpdateFieldValue("InTrackingAlias", "<a href=\"https://www.fedex.com/fedextrack/?cntry_code=us&tab=1&tracknums="
+ InTracking
+ "&clienttype=dotcom\" target='_blank'>"
+ InTracking
+ "</a>");
break;
case 18:
// UPS
UpdateFieldValue("InTrackingAlias", "<a href=\"http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_US&InquiryNumber1="
+ InTracking
+ "&clienttype=dotcom\" target='_blank'>"
+ InTracking
+ "</a>");
break;
// This is the placeholder for method implementation.
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
Now we see that the constants are redundant:
Open in new window
Step 2: What are the parameters {In|Out}TrackingAlias for?
Step 3: I would rewrite it as
Open in new window
The keyword rule and the repeating code seems to like you should look into the strategy pattern and the chain of responsibility pattern.