C# Decisions - Applications

 

Magic 8 Ball and the ListBox

A while back when we were learning how the Switch statement works, we created an application called “The Famous Magic 8 Ball”.  In that program a user could ask a question and then click on the Magic 8 Ball to get a magic answer from the 8 ball.  To do that we used the SWITCH statement.  Without the switch we would have had to use a series of IF statements, or a long drawn-out series of IF/ELSE/IF statements.  It would have been a lot of code.

Well, the switch statement shortened that code and made the logic a bit more elegant and easy to follow.  But quite frankly, there is a way to eliminate all the code in that switch statement are replace it with three lines of code.