2
有沒有辦法隱藏基類的成員?'刪除'基本成員?
class A
{
public int MyProperty { get; set; }
}
class B : A
{
private new int MyProperty { get; set; }
}
class C : B
{
public C()
{
//this should be an error
this.MyProperty = 5;
}
}
沒有。 [C#歸因於LSP](http://en.wikipedia.org/wiki/Liskov_substitution_principle)。可以做的最好的事情是拋出異常;或者在某些情況下使用更精細的接口。 – 2012-05-25 02:27:36
@pst:Eric Lippert在一些討論中已經很清楚地表明C#中的子類型不使用Liskov定義。 –
我很好奇爲什麼你會想要這樣做。 – casablanca