我該如何解決這個錯誤?如何解決「方法沒有超載」需要0個參數「?
「方法'輸出沒有超載需要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();
}
}
}
我想不出一個更全面的錯誤信息......什麼是你不明白? –
fresh.output();傳遞參數,它應該像output(double o,double tw,double th,double f); – Anand
錯誤信息不清楚? –