0

What to do if a code has many switches?

Switches... switches... switches...

18th Jan 2017, 8:01 PM
Phelipe Tisoni
11 Answers
+ 10
Ternary operators, RegEx, multiple conditions, try-catch……
18th Jan 2017, 8:26 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 9
Replace them with "if-else" ??
18th Jan 2017, 8:06 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 8
Well…… are there any other options??
18th Jan 2017, 8:11 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 6
Nothing that I can think of would make your code run faster. I guess it depends on the speed of the processor you have.
18th Jan 2017, 8:20 PM
J.G.
J.G. - avatar
+ 6
There might be something else based on your specific situation, but it would for sure require changing other things in your code (probably adding another class or two) I think you could just have another class and use a reference from their to do things, instead of having switches. But I'm not a c# programmer.
18th Jan 2017, 8:27 PM
J.G.
J.G. - avatar
+ 1
i don't know for certain if it is possible, but perhaps a while-loop could do the job? a while loop that will return your cases for the switch?
18th Jan 2017, 8:34 PM
kj loosman
kj loosman - avatar
0
but the code will do slowly?
18th Jan 2017, 8:10 PM
Phelipe Tisoni
0
I do not know ... the code has many switches and I do not know what would be better
18th Jan 2017, 8:16 PM
Phelipe Tisoni
0
Is there a way to decrease the number of switches?
18th Jan 2017, 8:25 PM
Phelipe Tisoni
0
thanks for help me ^^
18th Jan 2017, 8:28 PM
Phelipe Tisoni
0
The code is a virtual assistant that uses switches with strings to respond to commands. But now there are many commands and the code has many switches
18th Jan 2017, 8:42 PM
Phelipe Tisoni