看來,我得到一個錯誤消息:「產品不包含一個構造函數0參數不包含一個構造函數0參數
public class Products
{
string id;
string name;
double price;
int soldCount;
int stockCount;
public Products(string id, string name, double price,
int soldCount, int stockCount, double tax)
{
this.id = id;
this.name = name;
this.price = price;
this.soldCount = soldCount;
this.stockCount = stockCount;
}
}
//I have got some get and set values for the code above
//but it would have been too long to put in here
public class FoodProducts : Products
{
public FoodProduct()
{
Console.WriteLine("This is food product");
}
public void Limit()
{
Console.WriteLine("This is an Attribute of a Product");
}
}
上課通常的命名約定是單數,不是複數(如:'Product',而不是'Products'),因爲一個類定義類型,然後可以實例化。無論你是否擁有更多這些,都不應該成爲命名約定的一部分。 –
可能重複的[C#錯誤:父母不包含一個構造函數,它需要0參數](http://stackoverflow.com/questions/7230544/c-sharp-error-parent-does-not-contain-a-constructor- that-takes-0-arguments) – nawfal