【发布时间】:2021-07-18 09:27:09
【问题描述】:
我刚学C#,用构造函数做了两个外部类,一个继承自另一个。但它给出了错误: 严重性代码 描述 项目文件行抑制状态 错误 CS7036 没有给出与 'Engineer.Engineer(string)' program.cs C:\Users\win 10\Desktop\C#\program.cs\program.cs\Car 所需的形参 'i' 对应的参数.cs 41 活动 三个代码文件是: 1/ main.cs:
using System;
namespace program
{
class Core
{
static void Main(string[] args)
{
Car BMW = new Car("X-A-21-A-X", 3200000, "Reddish-brown", false);
string currentPrice = BMW.CheckPrice("us", BMW.price);
if(!double.TryParse(currentPrice, out var q))
{
Console.WriteLine(currentPrice);
}else if(double.TryParse(currentPrice, out var z))
{
double converted_Price = Convert.ToDouble(currentPrice);
Console.WriteLine(converted_Price);
}
Console.WriteLine(BMW.model);
}
}
}
2/ Car.cs:
using System;
namespace program
{
class Car : Engineer
{
private string _model;
public string model
{
get { return _model; }
set { _model = value; }
}
public double price;
public string color;
public bool available;
public string CheckPrice(string locale, double price)
{
string ret = default(string);
if(locale == "in")// India
{
ret = Convert.ToString(2.14 * price);
}else if(locale == "us")// USA
{
ret = Convert.ToString(3.98 * price);
}else if(locale == "jp")// Japan
{
ret = Convert.ToString(1.3 * price);
}else if(locale == "vn")//Vietnam
{
ret = Convert.ToString(0.78645 * price);
}else if(locale == "ch")//China
{
ret = Convert.ToString(2.56 * price);
}
else
{
ret = "Invalid Locale, Your Country does not ship the car.";
}
Console.WriteLine(_model);
return ret;
}
public Car(string modelName, double priceVal, string ColorName, bool avail) /* 'Car' in this line is causing problems*/
{
model = modelName;
price = priceVal;
color = ColorName;
available = avail;
}
}
}
3/ Engineer.cs:
using System;
namespace program
{
class Engineer
{
private string creatorCompany;
public string creator_Company
{
get { return creatorCompany; }
set { creatorCompany = value; }
}
public Engineer(string i)
{
creator_Company = i;
}
}
}
那里有答案,但我无法理解。请给我解释一下,就像我是一个不知道sh*t的和尚一样
【问题讨论】:
-
尝试在工程师类
public Engineer() { }添加默认构造函数@ -
@viveknuna 我已经添加了
标签: c# inheritance parameters constructor public