小编use*_*490的帖子

不包含带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 …
Run Code Online (Sandbox Code Playgroud)

inheritance c#-4.0

35
推荐指数
4
解决办法
8万
查看次数

不一致的可访问性:基类比类不易访问

我有下面的代码,我正在尝试做一些继承练习,但是当我尝试运行这段代码时,它给了我一个错误:

Inconsistent Accessability: Base Class is less accessible than class
Run Code Online (Sandbox Code Playgroud)

代码:

class Program
{
    static void Main()
    {

        FoodProducts Test = new FoodProducts();

        Test.Limit();



    }
}

public class FoodProducts : Products
{
    public void FoodProduct()
    {
        Console.WriteLine("This is food product");
    }

    public void Limit()
    {
        Console.WriteLine("This is an Attribute of a Product");
    }

}
Run Code Online (Sandbox Code Playgroud)

有人能帮助我吗?

c# inheritance

6
推荐指数
4
解决办法
3万
查看次数

MyFunction()未捕获参考错误

错误:未捕获的ReferenceError:未定义myFunction

这是我的.js文件无效或调用我的HTML

function = myFunction() 
{
    var ret = "";
    for (var i = 15; i < 26; i++) 
    {
        ret += i + "  " + i*2 + "  " + i*3 + "\n";    
    }
    alert(ret);
}
Run Code Online (Sandbox Code Playgroud)

这是我的HTML代码:

<!DOCTYPE HTML>
<html>

<head>
<script type="text/javascript" src="Test1.js"></script>

</head>

<body>

<h1> Exercise 4 - LAB 4  </h1>

<h2> Exercise 2.1 </h2>

<button type="button" onclick= "myFunction() "> Press Me </button>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

错误:未捕获的ReferenceError:未定义myFunction

javascript

1
推荐指数
1
解决办法
943
查看次数

继承打印两次,但从而开始

嘿家伙我不知道当我从主要的代码启动我的控制台时,它打印项目两次不确定,因为我根本没有循环方法:

        FoodProducts FoodProd1 = new FoodProducts("FP001", "Meat", 15.99, 200, 100, "Australia");
        FoodProducts FoodProd2 = new FoodProducts("FP002", "Bread", 2.99, 150, 50, "Italy");

        FoodProd1.Print();
        FoodProd2.Print();

class FoodProducts : Products
{

    private string origin;

    public FoodProducts(string id, string name, double price, int soldCount, int stockCount, string origin)
        : base(id, name, price, soldCount, stockCount)
    {
        this.origin = origin;
        //Need to find out why this code prints both lines and not in single line and why it starts from Product 2 when it is printed …
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
124
查看次数

标签 统计

c# ×2

inheritance ×2

c#-4.0 ×1

javascript ×1