我需要将一个开关与一个if语句结合起来。
我该怎么做?我想做这样的事情:
switch (periodtype)
{
if(starttime>endtime)
{
;
}
else
{
case 0: nextRunTime = nextRunTime.AddHours(period); break;
case 1: nextRunTime = nextRunTime.AddMinutes(period); break;
case 2: nextRunTime = nextRunTime.AddSeconds(period); break;
}
}
答案 0 :(得分:15)
出了什么问题:
if(starttime<=endtime)
{
switch (periodtype)
{
case 0: nextRunTime = nextRunTime.AddHours(period); break;
case 1: nextRunTime = nextRunTime.AddMinutes(period); break;
case 2: nextRunTime = nextRunTime.AddSeconds(period); break;
}
}
答案 1 :(得分:2)
if(starttime>endtime)
{
// Stuff
}
else
{
switch (periodtype)
{
case 0: nextRunTime = nextRunTime.AddHours(period); break;
case 1: nextRunTime = nextRunTime.AddMinutes(period); break
case 2: nextRunTime = nextRunTime.AddSeconds(period); break;
}
}
喜欢那个?
答案 2 :(得分:1)
if(starttime>endtime)
{
;
}
else
{
switch (periodtype)
{
case 0: nextRunTime = nextRunTime.AddHours(period); break;
case 1: nextRunTime = nextRunTime.AddMinutes(period); break;
case 2: nextRunTime = nextRunTime.AddSeconds(period); break;
}
}
答案 3 :(得分:0)
if(starttime <= endtime)
{
switch (periodtype)
{
case 0: nextRunTime = nextRunTime.AddHours(period); break;
case 1: nextRunTime = nextRunTime.AddMinutes(period); break;
case 2: nextRunTime = nextRunTime.AddSeconds(period); break;
}
}
答案 4 :(得分:0)
回答
太迟了这不容易:
if (starttime <= endtime)
{
switch (periodtype)
{
case 0: nextRunTime = nextRunTime.AddHours(period); break;
case 1: nextRunTime = nextRunTime.AddMinutes(period); break;
case 2: nextRunTime = nextRunTime.AddSeconds(period); break;
}
}