如何修复“找不到合适的方法来覆盖”以及如何使用数组
本文关键字:覆盖 数组 何使用 方法 何修复 找不到 | 更新日期: 2023-09-27 18:36:20
我在两个"输出"中不断收到错误"找不到合适的方法来覆盖"。我将如何解决这个问题?
如何使用数组将数字 4、5 和 6 放在第一句话中,将数字 7 放在第二句话中?
这是我到目前为止所做的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication_program
{
public class Numbers
{
public virtual void output()
{
}
}
public class IntegerOne : Numbers
{
public override void output(double o, double tw, double th)
{
one = o;
two = tw;
three = th;
}
}
public class IntegerTwo : Numbers
{
public override void output(double f)
{
four = f;
}
}
class program
{
static void Main(string[] args)
{
Numbers[] chosen = new Numbers[2];
chosen[0] = new IntegerOne(4, 5, 6);
chosen[1] = new IntegerTwo(7);
Console.WriteLine("First number is {0}, second number is {1}, and third number is {2}", ;
Console.WriteLine("Fourth number is {0}", ;
Console.ReadLine();
}
}
}
重写虚拟方法时,签名必须与被覆盖的方法匹配。
如果虚拟方法是:
virtual void Method( int a, int b ) { ... }
覆盖还必须具有相同的参数:
override void Method( int a, int b ) { ... }