diff --git a/appCs/src/ApiFunctions.cs b/appCs/src/ApiFunctions.cs index b4b4293..0104ab3 100644 --- a/appCs/src/ApiFunctions.cs +++ b/appCs/src/ApiFunctions.cs @@ -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); diff --git a/appCs/src/Program.cs b/appCs/src/Program.cs index d5495cc..45b6a8b 100644 --- a/appCs/src/Program.cs +++ b/appCs/src/Program.cs @@ -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(); @@ -270,23 +260,14 @@ private static void Calculate(IntPtr field) else if (new HashSet { "!", "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();