The code below represents what I am trying to write. The requirement is that the tax profile should match the correct currency. I have written the if conditions in my code below. However there are more than 100 tax profiles that are read via a database. Should I write if conditions for all 100 of them or is there a better way to code?
using System;
namespace MatchCondition
{
class MatchCondition
{
private const int TaxAmerica1 = 100;
private const int TaxAmerica2 = 200;
private const int TaxIndia1 = 300;
private const int TaxIndia2 = 400;
private const int Rupee =100;
private const int Dollar =200;
static void Main(string[] args)
{
try
{
int currencyId = int.Parse(args[0]);
int taxProfileId = int.Parse(args[1]);
if (currencyId == Rupee && (taxProfileId == TaxIndia1 || taxProfileId == TaxIndia2))
{
Console.WriteLine("All is well!");
}
else if(currencyId == Dollar && (taxProfileId == TaxAmerica1 || taxProfileId == TaxAmerica2))
{
Console.WriteLine("All is well!");
}
else if (taxProfileId == 0)
{
Console.WriteLine("All is well!");
}
else
{
Console.WriteLine("Mismatch Detected!");
}
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
}
}
}
You can put all your valid combinations in a hashtable, i.e.
IDictionaryand go from there.For example:
You could also populate the dictionary with combinations read from a database table, so you don’t have to hardcode them. YMMV.