简体   繁体   English

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

[英]How to fix “No overload for method ' ' takes 0 arguments”?

How can I fix this error? 我该如何解决这个错误?

"No overload for method 'output' takes 0 arguments". “方法'输出'没有重载需要0个参数”。

The error is at the very bottom at "fresh.output();". 错误位于“fresh.output();”的最底部。

I don't know what I'm doing wrong. 我不知道我做错了什么。 Can someone tell me what I should do to fix the code? 谁能告诉我应该怎么做才能修复代码?

Here is my code: 这是我的代码:

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();
        }
    }
}

It's telling you that the method "output" needs arguments. 它告诉你方法“输出”需要参数。 Here's the signature for "output": 这是“输出”的签名:

public override void output(double o, double tw, double th, double f)

So if you want to call that you need to pass in four doubles. 因此,如果你想打电话,你需要传递四个双打。

fresh.output(thing1,thing2,thing3,thing4);

Or to use hard coded values as an example: 或者使用硬编码值作为示例:

fresh.output(1,2,3,4);

There's no method named output that takes 0 arguments, there's only one that accepts 4 arguments. 没有名为output的方法接受0个参数,只有一个接受4个参数。 You must pass parameters to output() : 您必须将参数传递给output()

foreach (Numbers fresh in chosen)
{
    fresh.output(o, tw, th, f);
}

You're calling the output method with 0 (zero) parameters, but you have declared it to receive 4 double values. 您使用0(零)参数调用output方法,但您已声明它接收4个双精度值。 The compiler doesn't know what it should call, since there is no output method with no parameter. 编译器不知道它应该调用什么,因为没有没有参数的output方法。

All your implementations of method output takes arguments. 所有方法output的实现都需要参数。 Supply the arguments and you should be able to compile. 提供参数,你应该能够编译。

Like this: 像这样:

fresh.output(1, 2, 3, 4);

fresh.output() 2个参数而你没有提供它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM