我们如何将下面的 if -else 语句切换为 switch case 语句..任何人都可以帮忙解决这个问题...
if (Webcc1.Contains(licensePartID))
{
dtExpiryDate = dtActivatedDate.AddYears(1);
int isExpiry = DateTime.Compare(dtActivatedDate, dtExpiryDate);
if (isExpiry >= 0)
{
setError(lblSystemErr, "This action cannot be performed. The subscription period of the license key has expired");
return;
}
}
else if (Webcc3.Contains(licensePartID))
{
dtExpiryDate = dtActivatedDate.AddYears(3);
int isExpiry = DateTime.Compare(dtActivatedDate, dtExpiryDate);
if (isExpiry >= 0)
{
setError(lblSystemErr, "This action cannot be performed. The subscription period of the license key has expired");
return;
}
}
else if (Webcc5.Contains(licensePartID))
{
dtExpiryDate = dtActivatedDate.AddYears(5);
int isExpiry = DateTime.Compare(dtActivatedDate, dtExpiryDate);
if (isExpiry >= 0)
{
setError(lblSystemErr, "This action cannot be performed. The subscription period of the license key has expired");
return;
}
}
提前谢谢了 ....
您不能直接执行此操作,但可以使用 按位运算 三元条件将 if...else if 转换为 switch 语句:
罢工>
var flags = (Webcc1.Contains(licensePartID)) ? 1 : 0;
flags |= (Webcc3.Contains(licensePartID)) ? 2 : 0;
flags |= (Webcc5.Contains(licensePartID)) ? 4 : 0;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)