【发布时间】:2015-08-01 23:46:53
【问题描述】:
我正在使用从接口实现的类。 我想从接口实现一个属性,但出现错误:
类“ListManager”必须为接口“IListManager(Of T)”实现“Property Count As Integer”。实现属性必须具有匹配的“ReadOnly”或“WriteOnly”说明符。
界面:
Namespace Assign_1
Public Interface IListManager(Of T)
''' <summary>
''' Return the number of items in the collection m_list
''' </summary>
Property Count As Integer
End Namespace
类:
Namespace Assign_1
Public Class ListManager(Of T)
Implements IListManager(Of T)
Protected m_list As List(Of T)
''' <summary>
''' Constructor
''' </summary>
Public Sub New()
MyBase.New()
m_list = New List(Of T)
End Sub
''' <summary>
''' Property to count the list
''' </summary>
Public ReadOnly Property Count As Integer
Get
Return m_list.Count
End Get
End Property
End Namespace
有人知道这个问题吗?
【问题讨论】:
-
要么在接口定义中设为 ReadOnly,在类中删除 readonly,或者更好的是,让它成为一个函数
-
我尝试在接口定义中将其设为 ReadOnly,删除类中的只读。它没有用。我不明白您所说的“全方位制作功能”是什么意思
标签: vb.net