如何修复"方法没有重载"需要0参数"?

Use*_*ser 4 c# console-application

我该如何解决这个错误?

"方法'输出'没有重载需要0个参数".

错误位于"fresh.output();"的最底部.

我不知道我做错了什么.谁能告诉我应该怎么做才能修复代码?

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication_program
{
    public class Numbers
    {
        public double one, two, three, four;
        public virtual void output(double o, double tw, double th, double f)
        {
            one = o;
            two = tw;
            three = th;
            four = f;
        }
    }
    public class IntegerOne : Numbers
    {
        public override void output(double o, double tw, double th, double f)
        {
            Console.WriteLine("First number is {0}, second number is {1}, and third number is {2}", one, two, three);
        }
    }
    public class IntegerTwo : Numbers
    {
        public override void output(double o, double tw, double th, double f)
        {
            Console.WriteLine("Fourth number is {0}", four);
        }
    }
    class program
    {
        static void Main(string[] args)
        {
            Numbers[] chosen = new Numbers[2];

            chosen[0] = new IntegerOne();
            chosen[1] = new IntegerTwo();

            foreach (Numbers fresh in chosen)
            {
                fresh.output();
            }     
            Console.ReadLine();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Bil*_*egg 10

它告诉你方法"输出"需要参数.这是"输出"的签名:

public override void output(double o, double tw, double th, double f)
Run Code Online (Sandbox Code Playgroud)

因此,如果你想打电话,你需要传递四个双打.

fresh.output(thing1,thing2,thing3,thing4);
Run Code Online (Sandbox Code Playgroud)

或者使用硬编码值作为示例:

fresh.output(1,2,3,4);
Run Code Online (Sandbox Code Playgroud)


Chr*_*tle 6

没有指定的方法output接受 0 个参数,只有一个方法接受 4 个参数。您必须将参数传递给output()

foreach (Numbers fresh in chosen)
{
    fresh.output(o, tw, th, f);
}
Run Code Online (Sandbox Code Playgroud)