.net错误:实现属性必须具有匹配的“ReadOnly”或“WriteOnly”说明符

时间:2011-03-09 17:29:38

标签: vb.net interface

尝试在vb.net中实现接口时出现此错误:

Public Interface IFoo
   ReadOnly Property Foo() As String
End Interface

Public Class myFoo
  Implements IFoo

  Public ReadOnly Property Foo() As String
     Get
       return "Foo"
     End Get
  End Property
...
End Class

缺少什么?

1 个答案:

答案 0 :(得分:20)

您需要告诉代码myFoo.Foo实现IFoo.Foo(注意添加的Implements IFoo.Foo):

Public Interface IFoo
    ReadOnly Property Foo() As String
End Interface

Public Class myFoo
    Implements IFoo

    Public ReadOnly Property Foo() As String Implements IFoo.Foo
        Get
            Return "Foo"
        End Get
    End Property
End Class

据我所知,VB.NET不支持隐式接口实现,就像C#一样。