【发布时间】:2016-02-29 21:29:59
【问题描述】:
我是 C# 新手,并试图弄清楚继承是如何工作的。我收到以下错误。为什么父参数必须是静态的?
严重性代码描述项目文件行抑制状态 错误 CS0120 非静态字段需要对象引用, 方法或属性 'Rectangle.name' PurrS PATH\Sign.cs 15 Active
家长:
namespace PurrS.Maps
{
public class Rectangle
{
protected string name;
protected int id;
protected float a;
protected float b;
protected float c;
protected float d;
protected int posX;
protected int posY;
//A----B
//| |
//C----D
public Rectangle(string name, int id, float a, float b, float c, float d, int posX, int posY)
{
this.name = name;
this.id = id;
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
}
}
孩子:
namespace PurrS.Maps
{
public class Sign : Rectangle
{
string message;
public Sign(string message)
: base(name, id, a, b, c, d, posX, posY) { //This is where it fails.
this.message = message;
}
}
}
【问题讨论】:
标签: c# inheritance