Day 10: Switch statements in C#

Jake Boere
2 min readMay 11, 2021

Objective: We need to use switch statements when we have to many if statements that don’t handle input.

We are going to change the code above to match the switch statement at the top. To do this we need to have a common variable which will be the points which we put in the brackets and then for each different case we put the different outputs that can happen.

This is the input I have set up to trigger each case.

So, in the first case when I hit the Q key I’ll give myself 50 points so I want to display that in the console when it happens to show it works and I want the same for when I press the W and E keys. So, for the first case in the program we want to write case 50 because it will be the fiftieth case technically since case 1 would be if we had one point. We also need a break between each case to show the program that that’s the end of the case and we can move on to the next one. The default case can be used just to null check.

--

--

Jake Boere

I am hard working Game development student learning as much about game development and unity as possible.