I have a C# program that maps legacy text file report to an excel sheet. it works but it takes too long to run.
I wasn’t sure how but i read that one problem is using the IF statement that I should change that to the SWITCH clause. How do i do that?
here is a typical case.
else if (line.Contains("BILLING PARTY 1")) {
string billingParty1 = line.Replace("BILLING PARTY 1", "");
if (!string.IsNullOrWhiteSpace(billingParty1)){
patient.BillingParty1 = billingParty1.Trim();
}
}
That advice doesn’t look like it applies here. You can use a
switchstatement to replace a long chain ofifs where you are checking to see if a field matches some value. For example:becomes
In this case, it’s likely the compiler could generate faster code. But it seems like you have some more complicated conditions in your
ifstatements as opposed to simple equality, so you won’t be able to use aswitch, because in aswitch,MS Ref