我的秋季学期将包括使用 c#,所以我正在努力争取尽可能的优势。我想做的第一件事是了解抽象类,但我在使我的代码工作时遇到困难。它是一个“item”类,有 3 个 .cs 文件,包括主项目类。
这是抽象类。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6
{
abstract public class item
{
public abstract string prodName { set; }
public abstract int amount();
}
}
这是子类。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6
{
public class ProteinPowder : item // Says it doesn't implement anything.
{
private string name;
private int itemAmount;
public proPowder(string name, int amount) // Is this correct?
{
this.name = name;
this.itemAmount = amount;
}
public string Name { set => name = value; }
public int Amount { set => itemAmount = value; }
}
}
主项目目前是空的。我认为可以通过正确实施 ProteinPowder 来解决这些问题,但我无法让它发挥作用。有人可以指出我做错了什么吗?
** 编辑 ***
这看起来更好吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6
{
public class ProteinPowder : item
{
private string name;
private int itemAmount;
public ProteinPowder(string name, int amount)
{
this.name = name;
this.itemAmount = amount;
}
public int Amount { set => itemAmount = value; }
public override string prodName { set => throw new NotImplementedException(); }
public override int amount()
{
throw new NotImplementedException();
}
}
}
宝慕林4294392
相关分类