Skip to content

Commit 768f7bc

Browse files
committed
Replace switch with if-else in Calc.cs
1 parent 1238a7c commit 768f7bc

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

dotnet_3/cs/rest/SCS/Imp/Calc.cs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,32 @@ public static string Subject(string op, double arg1 , double arg2 )
88
{
99
op = op.ToLower();
1010

11-
var result = op switch
12-
{
13-
"pi" => Math.PI,
14-
"e" => Math.E,
15-
"sqrt" => Math.Sqrt(arg1),
16-
"log" => Math.Log(arg1),
17-
"sine" => Math.Sin(arg1),
18-
"cosine" => Math.Cos(arg1),
19-
"tangent" => Math.Tan(arg1),
20-
"plus" => arg1 + arg2,
21-
"subtract" => arg1 - arg2,
22-
"multiply" => arg1 * arg2,
23-
"divide" => arg1 / arg2,
24-
_ => 0.0
25-
};
26-
11+
double result;
12+
if (op == "pi")
13+
result = Math.PI;
14+
else if (op == "e")
15+
result = Math.E;
16+
else if (op == "sqrt")
17+
result = Math.Sqrt(arg1);
18+
else if (op == "log")
19+
result = Math.Log(arg1);
20+
else if (op == "sine")
21+
result = Math.Sin(arg1);
22+
else if (op == "cosine")
23+
result = Math.Cos(arg1);
24+
else if (op == "tangent")
25+
result = Math.Tan(arg1);
26+
else if (op == "plus")
27+
result = arg1 + arg2;
28+
else if (op == "subtract")
29+
result = arg1 - arg2;
30+
else if (op == "multiply")
31+
result = arg1 * arg2;
32+
else if (op == "divide")
33+
result = arg1 / arg2;
34+
else
35+
result = 0.0;
36+
2737
return "" + result;
2838
}
2939
}

0 commit comments

Comments
 (0)