我写了一些这样的 if-else语句:
if (workedDays > 0 && workedDays <= 180)
{
x= 14;
}
if (workedDays > 180 && workedDays <= 540)
{
x= 28;
}
if (workedDays > 540 && workedDays <= 1068)
{
x= 42;
}
else
{
x= 56;
}
我试图将其重写为switch语句,如下所示:
switch (workedDays)
{
case (workedDays > 0 && workedDays <= 180):
x=14;
break;
default:
break;
}
但是,我收到错误消息Cannot implicitly convert type 'bool' to 'int'
。
我该如何解决?