如何解决“方法'的重载不接受0个参数”? [英] How to fix "No overload for method ' ' takes 0 arguments"?
本文介绍了如何解决“方法'的重载不接受0个参数”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何解决此错误?
方法'output'的重载不接受0个参数。
"No overload for method 'output' takes 0 arguments".
错误在 fresh.output();的最底部。
The error is at the very bottom at "fresh.output();".
我不知道我在做什么错误。有人可以告诉我该怎么做才能修复代码吗?
I don't know what I'm doing wrong. Can someone tell me what I should do to fix the 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);
或者以硬编码值为例:
fresh.output(1,2,3,4);
这篇关于如何解决“方法'的重载不接受0个参数”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文