CS7036:There 没有给出对应于所需形式参数 'i' 的参数
CS7036:There is no argument given that corresponds to the required formal parameter 'i'
刚学C#,做了两个外部类构造函数,一个继承另一个。但它给出了错误:
严重性代码描述项目文件行抑制状态
错误 CS7036 没有给定的参数对应于 'Engineer.Engineer(string)' program.cs 的所需形式参数 'i' C:\Users\win 10\Desktop\C#\program.cs\program.cs\Car.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
的僧侣
您需要将默认构造函数添加到 Engineer
class。因为当您创建派生的实例时,它会在派生 class 构造函数之前调用基 class 构造函数。
public Engineer()
{
}
如果Car
是Engineer
在 Car
是 Engineer
的不太可能的情况下,Car
需要提供 creatorCompany
:
Engineer
定义指出必须提供 creatorCompany
Car
是 Engineer
Car
必须提供 creatorCompany
.
它可能看起来像这样:
public Car(
string creatorCompany, // Added
string modelName,
double priceVal,
string ColorName,
bool avail)
: base(i: creatorCompany) // Added
{
model = modelName;
price = priceVal;
color = ColorName;
available = avail;
}
如果Car
不是Engineer
在这种情况下,解决方法是去掉: Engineer
:
class Car : Engineer
变为:
class Car
我找到了答案,我只需要将engineer
的构造函数class添加到car
。我从 Engineer 文件中删除了构造函数,并向“Car”的构造函数添加了另一个参数并将其设置在那里。
刚学C#,做了两个外部类构造函数,一个继承另一个。但它给出了错误: 严重性代码描述项目文件行抑制状态 错误 CS7036 没有给定的参数对应于 'Engineer.Engineer(string)' program.cs 的所需形式参数 'i' C:\Users\win 10\Desktop\C#\program.cs\program.cs\Car.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
的僧侣您需要将默认构造函数添加到 Engineer
class。因为当您创建派生的实例时,它会在派生 class 构造函数之前调用基 class 构造函数。
public Engineer()
{
}
如果Car
是Engineer
在 Car
是 Engineer
的不太可能的情况下,Car
需要提供 creatorCompany
:
Engineer
定义指出必须提供creatorCompany
Car
是Engineer
Car
必须提供creatorCompany
.
它可能看起来像这样:
public Car(
string creatorCompany, // Added
string modelName,
double priceVal,
string ColorName,
bool avail)
: base(i: creatorCompany) // Added
{
model = modelName;
price = priceVal;
color = ColorName;
available = avail;
}
如果Car
不是Engineer
在这种情况下,解决方法是去掉: Engineer
:
class Car : Engineer
变为:
class Car
我找到了答案,我只需要将engineer
的构造函数class添加到car
。我从 Engineer 文件中删除了构造函数,并向“Car”的构造函数添加了另一个参数并将其设置在那里。