Friday, April 30, 2010

"Modified" Rotating ads automatically for every 10 minutes in ASP.Net C#

Found some solution to write compact code for the Rotating ads. This topic is to explain how well we can code this is called CLEVER programming.
In the previous topic there is If -Else ladder,



Now,
if (time == 0)
      tempTime = 1;
   else
       tempTime = (int)(Math.Floor((double)((time - 1) / 10)))+1;




Here Math.Floor cannot be used on integer so converting integer to double explicitly is necessary and then whole expression is converted to integer explicitly because "tempTime" is a integer variable,

The above code is replacement over this:

if (time >= 00 && time <= 10) //
              tempTime = 1; 
            else
                if (time >= 11 && time <= 20)
                    tempTime = 2;
                else
                    if (time >= 21 && time <= 30)
                        tempTime = 3;
                    else
                        if (time >= 31 && time <= 40)
                            tempTime = 4;
                        else
                            if (time >= 41 && time <= 50)
                                tempTime = 5;
                            else
                                   tempTime = 6;









No comments:

Post a Comment