这个问题是这个问题的附加问题
在 C# 中,一个 switch case 不能落入其他 case,这会导致编译错误。在这种情况下,我只是在所选月份以及之后的每个月份的月份总数中添加一些数字。(简单的例子,并不意味着是真实的)
switch (month)
{
case 0:
add something to month totals
case 1:
add something to month totals
case 2:
add something to month totals
default:
break;
}
在 C# 中是否有一个逻辑替代方案,而不必写出大量的 if 语句?
if (month <= 0)
add something to month
if (month <= 1)
add something to month
if (month <= 2)
add something to month
.... etc