我想写一下如果c#中的Else条件更短,你可以在下面观察我的代码吗'那么冗长..我想要用更短的方式写,帮助我任何人都知道.我们可以使用其他任何方式来写它吗?
int paymentType;
if (lblPayment.Text == "Credit")
{
paymentType = 1;
}
else if (lblPayment.Text == "Open Invoice")
{
paymentType = 2;
}
else if (lblPayment.Text == "COD")
{
paymentType = 3;
}
else if (lblPayment.Text == "Check")
{
paymentType = 4;
}
else if (lblPayment.Text == "Paypal")
{
paymentType = 5;
}
else if (lblPayment.Text == "Money Order")
{
paymentType = 6;
}
else if (lblPayment.Text == "Other")
{
paymentType = 7;
}
Run Code Online (Sandbox Code Playgroud) c# ×1