I'm studing C# now, and came across the following situation, what's the better pratice, duplicate the code like "EX 1" or use goto
statement like "EX 2"?
I don't want a personal opnion.
// EX 1:
switch (a)
{
case 3:
b = 7;
c = 3; // duplicate code <-|
break; // |
case 4: // |
c = 3; // duplicate code --|
break;
default:
b = 2;
c = 4;
break;
}
// EX 2:
switch (a)
{
case 3:
b = 7;
goto case 4; // not duplicate code and use goto statement
case 4:
c = 3;
break;
default:
b = 2;
c = 4;
break;
}