More language esoterica - falling through a switch statement
Not that I'm much of a comp-sci guy but, I do like my language esoterica... earlier I posted about repeating structures in C# and it got me thinking about other language features - many of which are shared between VB and C# such as short-circuit evaluation and such. One language feature which I thought was pretty cool that C# didn't implement was switch-case fall-through. I'll bet that was a tough one to leave out! Here's an example of using fall-through behaviour to convert a number of Days, Hours, Minutes, or Seconds toMilliseconds:
function ToMilliseconds( unit, interval ) { var number = unit ; switch (interval.charAt(0)) { case 'd': case 'D': number *= 24 ; // days to hours // fall through! case 'h': case 'H': number *= 60 ; // hours to minutes // fall through! case 'm': case 'M': number *= 60 ; // minutes to seconds // fall through! case 's': case 'S': number *= 1000 ; // seconds to milliseconds break ; default: // If we get to here then the interval parameter // didn't meet the d,h,m,s criteria. Handle // the error. alert(intervalMsg) ; return null ; } return number ; }