Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
Hummel009 committed Jan 19, 2024
1 parent 0efbbc2 commit 56ff533
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 34 deletions.
2 changes: 1 addition & 1 deletion appCs/src/ApiFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ IntPtr lpParam
public static extern bool SetWindowText(IntPtr hwnd, string? lpString);

[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder? lpString, int nMaxCount);
public static extern void GetWindowText(IntPtr hWnd, StringBuilder? lpString, int nMaxCount);

[DllImport("user32.dll")]
public static extern int GetWindowTextLength(IntPtr hWnd);
Expand Down
47 changes: 14 additions & 33 deletions appCs/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,14 @@ private static void Calculate(IntPtr field)

var operand1 = double.Parse(data[0]);
var operand2 = double.Parse(data[2]);

double result;
switch (op)

var result = op switch
{
case "+":
result = operand1 + operand2;
break;
case "-":
result = operand1 - operand2;
break;
case "*":
result = operand1 * operand2;
break;
case "/":
result = operand1 / operand2;
break;
default:
throw new Exception("Invalid operator: " + op);
"+" => operand1 + operand2,
"-" => operand1 - operand2,
"*" => operand1 * operand2,
"/" => operand1 / operand2,
_ => throw new Exception("Invalid operator: " + op),
};

data.Clear();
Expand All @@ -270,23 +260,14 @@ private static void Calculate(IntPtr field)
else if (new HashSet<string> { "!", "s", "i", "r" }.Contains(op))
{
var operand = double.Parse(data[0]);
double result;
switch (op)

var result = op switch
{
case "!":
result = FACTORIAL[(int)operand];
break;
case "s":
result = operand * operand;
break;
case "i":
result = 1.0 / operand;
break;
case "r":
result = Math.Sqrt(operand);
break;
default:
throw new Exception("Invalid operator: " + op);
"!" => FACTORIAL[(int)operand],
"s" => operand * operand,
"i" => 1.0 / operand,
"r" => Math.Sqrt(operand),
_ => throw new Exception("Invalid operator: " + op),
};

data.Clear();
Expand Down

0 comments on commit 56ff533

Please sign in to comment.