Question

Is C# true to C++, needing a break; per case:? ..Default is fall-thru - Unlike VB

OR will it automatically break out of a case once found? ..Default is break - Like VB


Edit: So it is a combination of both, Default is none - You have to specify either break; or goto;

Was it helpful?

Solution

Every case needs to have either a break; or goto case statement in C#

OTHER TIPS

You use a break in C#, just like in C++. However, if you omit the break you must replace it with another other control transfer (e.g. goto case 1;).

See http://msdn.microsoft.com/en-us/library/06tc147t(VS.71).aspx

It requires the break or you'll get a compiler error. You can have multiple cases with one block of code but control cannot fall through to the next case.

You need some statement, either break or goto.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top