+ 7
Why do not remove at all the use of break in switch?
Since fall-through is disabled in c#, the use of break is mandatory in C# and not optional as in C++. So, according to me, its use seems redundant and could be avoided changing the semantics of switch statement. Maybe it is used only for compatibility with old compiler and other languages. Is it true or there is other reasons? I found something about this here: http://stackoverflow.com/questions/3108888/why-does-c-sharp-have-break-if-its-not-optional
3 Respuestas
+ 1
there is an answer in the comments to that link. as i understand it, the authors:
1) removed fall through behaviour because it is a common cause of logic error at maintenance time.
2) make the break mandatory to avoid discrepency with other similar languages
+ 1
if break was not mandatory the language would behave differently to other language even though the code is similar.
this would be a huge source of errors when developers swap between languages.
0
If you would remove these break statements the processor of your computer would not understand when to stop, hence a lot of errors would occur