0
Switch
https://code.sololearn.com/cExgxEfg54gY/#cs Is it possible to go over from the case of the internal switch to the external switch?
8 ответов
+ 2
Mary_d9
I was thinking about using a method, that can accept a string array (of choices), and return an int (the chosen option). Would it be a feasible option in your case?
+ 2
Mary_d9
The method signature may look like this;
int GetMenuChoice(string[] choices)
In the method you display each array element on a different line. Then you ask the user to choose by entering a number which is valid amongst the choices.
e.g.
If the array has 5 elements, you can make the method to ask again if the user enters a number that is < 1 or is > 5. If the user enters a number between 1 and 5 the method will return the number. You know which choice was taken/chosen as you get this return value in the caller side.
That's the idea, but I'm not sure if it is feasible for your project : )
+ 1
you mean you need to use nested switch?
+ 1
nested switch are hard to manage, I think it would be better to use an if-statement with a do{} while. if you want to loop over and over.
+ 1
Mary_d9
Care to share about what or why the need to use nested `switch` statement?
+ 1
Ipang I need to make a menu, and so that selecting one item, another menu opens
+ 1
Ipang How to do it?
0
bahha🐧 yes