I have a group of consts, then I dynamically create a variable that is equal to one of the consts name. I need to call that const, I know I can use if else statements but I wanted to know if theres a better way Thanks!
public const int LifeBand1Standard = 78;
public const int LifeBand1Multi = 61;
public const int LifeBand2Standard = 71;
public const int LifeBand2Multi = 56;
public const int LifeBand3Standard = 62;
public const int LifeBand3Multi = 48;
public const int LifeBand4Standard = 56;
public const int LifeBand4Multi = 44;
public const int LifeBand5Standard = 45;
public const int LifeBand5Multi = 35;
// Band discounts/loads for trauma cover
public const int TraumaBand1Standard = 140;
public const int TraumaBand1Multi = 126;
public const int TraumaBand2Standard = 135;
public const int TraumaBand2Multi = 121;
public const int TraumaBand3Standard = 121;
public const int TraumaBand3Multi = 109;
public const int TraumaBand4Standard = 110;
public const int TraumaBand4Multi = 99;
public const int TraumaBand5Standard = 100;
public const int TraumaBand5Multi = 90;
protected float GetPercentageFromBand(int band)
{
var constantName = "Life";
if (IsTraumaCover == true)
{
constantName = "Trauma";
}
constantName += "Band" + band;
if (IsMultiLife == true)
{
constantName += "Multi";
}
else
{
constantName += "Standard";
}
// Constant should look something like LifeBand3Standard and will return the value of the const LifeBand3Standard
BandPercentage = InsuranceBandFetcher.constantName;
}