讓一些麻煩說我有這樣的例子:與子類的構造
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
但是我們看到的A類和類的構造函數B幾乎相同。只是this.Name是不同的。我怎麼能重寫B類?有什麼建議麼?謝謝
這是一個有點娛樂,每個人都已經張貼着複製無效的構造函數聲明'公共類B(字符串ID,INT大小){/ *東西* /}'答案:) –