我想编写一个接口类并像这样使用它
public Interface IFunction
property name as string
end interface
public class ModelFunction
implements IFunction
public property name as string
public sub new()
end class
*编辑(删除后面的句子为noob,感谢@damien_the_unbeliever指出这一点):但这是不可能得到的,因为vb.net界面中的属性必须是只读或写入(据我所知)它)*
我现在写了这个,但似乎有点不对劲:
public Interface IFunction
Readlonly property getName() as string
writeonly property writeName() as string
end interface
public class ModelFunction
implements IFunction
....
end class
任何人都有更好的解决方案吗?或者可以帮助我使用Interface类中的属性。已经在stackoverflow上阅读了一些文章,但没有一篇指出我正确的方向。
答案 0 :(得分:8)
这对我来说很好用:
Public Class Class1
Implements Thing
Property Gary As Int32 Implements Thing.Gary
Get
Return 10
End Get
Set(value As Int32)
End Set
End Property
End Class
Public Interface Thing
Property Gary As Int32
End Interface
Interface
的文档页面上甚至还有一个示例:
Interface IAsset
Event ComittedChange(ByVal Success As Boolean)
Property Division() As String
Function GetID() As Integer
End Interface