السلام عليكم،

تعلمت في السابق بعض اساسيات لغة C# وكان ذلك قبل أكثر من سنة ولقد نسيتها تمامًا لأني لم أعمل بها، ولكني بدأت قبل يوم والحمدلله توصلت لمرحلة جيدة، أريد أن اسأل كيف يمكنني تحسيين هذا الكود أكثر من هذا، لكي أتمكن من:

  1. إضافات عمليات جديدة مثل Cube، Square_root ... الخ

  2. تقليل كمية الكود المكتوبة.

وشكراً لكم، هذا هو الكود عبارة عن Console Application:

using System;

namespace Calculator
{
/* Simple calculator to make some operations, and it has authenticaion system
** when it start the user must provide the correct name and password to be able
** to access it.
*/
class Program
{
    static void Main(string[] args) {
        reAuth:
        int auth = authentication();
        if (auth == 1) {
            // Variables
            calcType();

            Console.ReadKey();
        } else {
            Console.WriteLine("Wrong credentials!");
            goto reAuth;
        }
    }
    static int authentication() {
        Console.Write("Enter your name: ");
        string name = Console.ReadLine();
        Console.Write("\nEnter your password: ");
        string pass = Console.ReadLine();

        if (name == "Ali" && pass == "123")
            return 1;
        else
            return 0;
    }
    static void calcType() {
        Console.WriteLine("Pick the number of operation you want?");
        Console.WriteLine("\n1- Addition\n2- Substraction.\n3- Division.\n4- Multiplication.\n");
        Console.Write("Your choice: ");
        int choice = Convert.ToInt32(Console.ReadLine());

        if (choice > 4 || choice < 1)
            Console.WriteLine("Wrong choice!");
        else
            calc(choice);
    }
    static void calc(int calcType) {
        Console.Write("Enter the first number: ");
        double num1 = Convert.ToDouble(Console.ReadLine());

        Console.Write("Enter the second number: ");
        double num2 = Convert.ToDouble(Console.ReadLine());

        double result = 0;
        switch (calcType) {
            case 1:
                result = num1 + num2;
                break;
            case 2:
                result = num1 - num2;
                break;

            case 3:
                result = num1 / num2;
                break;

            case 4:
                result = num1 * num2;
                break;
            }
            Console.WriteLine("The result of the operation = " + result);
        }
    }
}