我是C#的新手,并试图弄清楚继承是如何工作的。我收到以下错误。为什么父参数必须是静态的?C#继承和对象引用
严重性代码说明项目文件的线路抑制状态 错误CS0120的对象引用需要非静态字段, 方法或属性“Rectangle.name”咕噜咕噜PATH \ Sign.cs 15主动
家长:
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;
}
}
}
在这里我想参数会自动传递给父类。谢谢。 – Theletos