Ошибка: CS7036 Отсутствует аргумент, соответствующий требуемому формальному параметру
Что не так с моим кодом?
Смотрел разные решения, так и не понял. Отсутствует аргумент, "name" из "Drone.Drone.
class Program
{
static void Main(string[] args)
{
Vehicle drone = new Drone();
Vehicle archer = new Archer();
drone.DisplayInfo();
archer.DisplayInfo();
Console.ReadKey();
}
}
class Vehicle
{
public string Name { get; set; }
public string Weapon { get; set; }
public int PowerScore { get; set; }
public int EngenePower { get; set; }
public int VehicleId { get; set; }
public Vehicle()
{ }
public virtual void DisplayInfo() { }
}
class Drone : Vehicle
{
public Drone(string name, int vehicleId, string weapon, int powerScore, int engenePower)
{
VehicleId = 001;Name = "Droncarrier";PowerScore = 5000;Weapon = "drone Fuse";EngenePower = 540;
}
public override void DisplayInfo()
{
Console.WriteLine(VehicleId + " with " + Name + " has " + PowerScore + " and carrys weapon " + Weapon + " engine " + EngenePower);
}
}
class Archer : Vehicle
{
public Archer(string name, int vehicleId, string weapon, int powerScore, int engenePower)
{
VehicleId = 003;Name = "Miniarcher";PowerScore = 5000;Weapon = "crossbow";EngenePower = 430;
}
public override void DisplayInfo()
{
Console.WriteLine(VehicleId + " with " + Name + " has " + PowerScore + " and carrys weapon " + Weapon + " engine " + EngenePower);
}
}
Ответы (1 шт):
Автор решения: Qwertiy
→ Ссылка
У классов Drone и Archer конструкторы только с параметрами, о чём и говорит компилятор. А вот никакой ошибки про name в приведённом коде нет.
prog.cs(5,25): error CS1729: The type `Drone' does not contain a constructor that takes `0' arguments
prog.cs(26,12): (Location of the symbol related to previous error)
prog.cs(6,26): error CS1729: The type `Archer' does not contain a constructor that takes `0' arguments
prog.cs(37,12): (Location of the symbol related to previous error)