【发布时间】:2012-09-04 12:23:13
【问题描述】:
假设我有这个例子:
class A : SomeAbstractClassWithProperties
{
public A(string id, int size)
{
this.Name = "Name1";
this.Something = new SomethingElse(id, size);
}
//...some stuff
}
class B : A
{
public B(string id, int size)
{
this.Name = "Name2";
this.Something = new SomethingElse(id, size);
}
}
好吧,这行不通:
Inconsistent accessibility: base class A is less accessible than class 'B'
'A' does not contain a constructor that takes 0 arguments
但是正如我们所见,Class A 和 Class B 的构造函数几乎相同。只是 this.Name 不同。我如何重写B 类?有什么建议?谢谢你
【问题讨论】:
-
每个人都发布了复制无效构造函数声明
public CLASS B(string id, int size){/*stuff*/}的答案,这有点有趣:)
标签: c# .net inheritance constructor