C# 方法'没有重载;主要计算';接受2个参数

C# 方法'没有重载;主要计算';接受2个参数,c#,overloading,C#,Overloading,静态void Main(字符串[]参数) { int choice; choice = 0; double length; length = 0.00; double height; height = 0.00; //initiating variables double base1; base1 = 0.00; double width;

静态void Main(字符串[]参数) {

        int choice;
        choice = 0;

        double length;
        length = 0.00;

        double height;
        height = 0.00; //initiating variables

        double base1;
        base1 = 0.00;

        double width;
        width = 0.00;

        double radius;
        radius = 0.00;

        double total;
        total = 0.00;

        Console.WriteLine("What shape would you like to make?");
        Console.WriteLine("Please select one option (1, 2, 3, or 4)");
        Console.WriteLine("1. Square.");
        Console.WriteLine("2. Triangle.");          //menu on the console 
        Console.WriteLine("3. Rectangle.");
        Console.WriteLine("4. Circle.");

        choice = int.Parse(Console.ReadLine());

        if (choice == 1)
        {
            Console.WriteLine("Great! You chose Square.");
            Console.WriteLine("Let's help you calculate the area of a square.");
            Console.WriteLine("But first, we need to know the length of this square");
            Console.WriteLine("Enter the length(Integer, or Decimal value is just fine:");
            length = double.Parse(Console.ReadLine());
        }

        else if (choice == 2)
        {
            Console.WriteLine("Great! You chose Triangle.");
            Console.WriteLine("Let's help you calculate the area of a triangle.");
            Console.WriteLine("But first, we need to know the base and height of this triangle.");
            Console.WriteLine("Enter the base(Integer, or Decimal value is just fine):");
            base1 = double.Parse(Console.ReadLine());                                          //writing to the console depending on what choice
            Console.WriteLine("Enter the height(Integer, or Decimal value is just fine):");
            height = double.Parse(Console.ReadLine());
        }

        else if (choice == 3)
        {
            Console.WriteLine("Great! You chose Rectangle.");
            Console.WriteLine("Let's help you calculate the area of a rectangle.");
            Console.WriteLine("But first, we need to know the width and height of this rectangle.");
            Console.WriteLine("Enter the width(Integer, or Decimal value is just fine):");
            width = double.Parse(Console.ReadLine());
            Console.WriteLine("Enter the height(Integer, or Decimal value is just fine):");
            height = double.Parse(Console.ReadLine());
        }

        else if (choice == 4)
        {
            Console.WriteLine("Great! You chose Circle.");
            Console.WriteLine("Let's help you calculate the area of a circle.");
            Console.WriteLine("But first, we need to know the radius of this circle.");
            Console.WriteLine("Enter the radius(Integer, or Decimal value is just fine:"); 
            radius = double.Parse(Console.ReadLine());


        }



        Main_Calculations(args, total, base1, height, width, choice); //Sending Paramters to the next method
    }
    static void Main_Calculations(string[] args, double base1, double height, double width, double total, int choice) //bringing in parameters 
    {



        if(choice == 2)
        {
            total = (base1 * height) * 0.5; //Calculations for triangle

            Console.WriteLine("The area of a triangle is: " + total);
        }

        else if(choice == 3)
        {
            total = width * height; //calculations for rectangle

            Console.WriteLine("The area of a rectangle is: " + total);
        }


           Main_Calculations(choice, total); //Sending Paramters to the next method
    }

        static void Main_Calculations(double length, double radius, double total, double choice)
        {


        if(choice == 1)
        {
            total = length * length; //Calculations for square

            Console.WriteLine("The area of a square is: " + total);
        }

        else if(choice == 4)
        {
            total = (radius * radius) * 3.14; //calculations for circle

            Console.WriteLine("The area of a circle is " + total); //prints the answer to the console
        }


        }
    }
}

我的第二个发件人(Math_Calculations)给了我一个错误,因为没有重载需要2个参数,我不明白为什么它不能按我的方式工作。似乎我只是缺少了一个短语,我已经在代码中进进出出,希望现在有用。

这将更容易用行号回答,但您可以调用

主要计算(选择、总计)


当主计算没有包含两个参数的方法时。正如Habib所指出的。

当调用第二个方法Math\u Calculations时,当您在方法中请求4个参数时,您只为该方法提供2个参数
因此,您需要做的是,或者,为2dn Math_Calculations调用额外提供2个参数,或者从该方法中删除2个参数。

因为“方法'Main_Calculations'不存在重载,它需要2个参数”。您有
Main_计算(双倍长度、双倍半径、双倍总数、双倍选择)
Main_计算(字符串[]args,双基1,双倍高度,双倍宽度,双倍总计,整数选择)
好吧,还有
静态空区主要计算(双倍长度,双倍半径,双倍总计,双倍选择)
-但同样,这没有两个参数…我该如何解决这个问题?一个解决方案是简单地将主计算的一些参数设置为可选。请参阅