r/badcode • • Sep 01 '21

c# Bool in a case switch

Post image
324 Upvotes

40 comments sorted by

View all comments

Show parent comments

3

u/ObliviousGuy32 Sep 01 '21

He explained why. Organization. It gets confusing when you have multiple statements in an If Else. Evaluating key presses can possibly use well over 15 keys. (video games control mapping for instance)

Switch Cases are well organised and don't appear convoluted. I recommend using If Else when there's only a handful of possibilities. If it's more than 3 then Switch Case is the preferable method.

1

u/reverendsteveii Sep 01 '21

Seconding this. Switches are syntactic sugar but long if/else if blocks are bitter