98-361 · Question #337
You are writing a C# program. You write the following method: public static void TestSwitch(int op1, int op2, char opr) { int result; switch (opr) { case '+': result = op1 + op2; case '-': result =…
The correct answer is A. After each case, add the following code line. See the full explanation below for the reasoning.
Question
You are writing a C# program. You write the following method:
public static void TestSwitch(int op1, int op2, char opr) { int result; switch (opr) { case '+':
result = op1 + op2; case '-':
result = op1 - op2; case '*':
result = op1 * op2; case '/':
result = op1 / op2; default:
Console.WriteLine("Unknown Operator"); return; } Console.WriteLine("Result: {0}", result); return; } However, when you compile this code, you get the following error message:
Control cannot fall through from one case label to another How should you modify the code to make sure that it compiles successfully?
Options
- AAfter each case, add the following code line:
- BAfter each case, add the following code line:
- CAfter each case, add the following code line:
- DAfter each case, add the following code line:
How the community answered
(14 responses)- A71% (10)
- B7% (1)
- C14% (2)
- D7% (1)
Community Discussion
No community discussion yet for this question.