Switch and Case query!?

Babayaga

New member
Joined
Mar 16, 2021
Messages
1
Programming Experience
Beginner
Hi all,

I am wondering if I can use a case statement to do more.

I'm using a switch to allow menu selection of some variables, but I have only attached a WriteLine to the case.
switch (moneyMM)
{
case 1:
Console.WriteLine("£10.00 Added to total, Add more ? Y or N ");
break;

My question is, can I use this case to add that £10 to a total, while allowing the return Y or N to the menu to add more money??

I'm scouring the internet for clues, so any help would be appreciated.
Regards,
Babayaga
 
Yes, you can.

The problem seems to be that you are scouring the Internet instead of actually reading the documentation.
A switch statement includes one or more switch sections. Each switch section contains one or more case labels (either a case or default label) followed by one or more statements
(emphasis mine).
 
It's generally better to keep each case fairly short so it may be a good idea to put all the code you wanted executed when moneyMM is 1 into a method and then call that method in that case. If it's only two or three lines though, putting it directly in the case is fine.
 

Latest posts

Back
Top Bottom