views:

605

answers:

5

I need to combine a switch with an if-statement.

How can I do that? I want to do something like this:

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;
    }
}
+2  A: 
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;
    }
}

Like that?

Bart S.
+12  A: 

What's wrong with:

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;
    }
}
Rowland Shaw
+1  A: 
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;
   }
}
Neil Fitzgerald
A: 
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;

       }
}
BobbyShaftoe
the if statement is wrong, just a small typo
PoweRoy
A: 

Hmm way too late with answer

isnt this easier:

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;
    }
}
PoweRoy