I have the following code with switch case statement:
public string IrregularCouponLabel
{
get
{
switch ((ctrl.IrregularCouponFirst ? 10 : 0) + (ctrl.IrregularCouponLast ? 1 : 0))
{
case 11: return LocalString.Evaluate("label.Both");
case 10: return LocalString.Evaluate("label.First");
case 1: return LocalString.Evaluate("label.Last");
default: return LocalString.Evaluate("label.None");
}
}
}
How should I refactor this code to be more clear and readable or how could I otherwise improve this code snippet?
UPDATE According to valuable answers I have updated the code in the following way,
public string IrregularCouponLabel
{
get
{
return LocalString.Evaluate("label." + GetIrregularCouponValue());
}
}
private string GetIrregularCouponValue()
{
bool first = ctrl.IrregularCouponFirst;
bool last = ctrl.IrregularCouponLast;
bool both = first && last;
return both ? "Both" :
first ? "First" :
last ? "Last" :
"None";
}
What do you think about this? Is it readable or not?