在C#以下工作:爲什麼VB.NET中的實現屬性必須匹配'ReadOnly'說明符?
interface I
{
int X { get; }
}
class C : I
{
public int X
{
get { ... }
set { ... }
}
}
下在VB.NET不起作用:
Interface I
ReadOnly Property X As Integer
End Interface
Class C
Implements I
Public Property X As Integer Implements I.X
Get
...
End Get
Set(value As Integer)
...
End Set
End Property
End Class
錯誤消息Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers
是不言自明的,所以我知道什麼是錯在這裏。這也不是一個大問題,因爲解決這個限制很容易。
我很好奇,但:有誰知道爲什麼VB設計師決定以不同於C#的方式處理這種情況?
我在界面的C版本中看不到您的屬性中的只讀屬性? – Nikki9696
@ Nikki9696:基本上C#版本中缺少setter是等價的。 –
@ Nikki9696暗示。不同之處在於它不需要。但是,Heinzi,你明確地在VB.NET界面版本中指定它,所以這是一個非常大的差異。 –