【发布时间】:2011-06-07 20:16:37
【问题描述】:
我有一个实现 IWeightable 的实体类:
Public Interface IWeightable
Property WeightState As WeightState
End Interface
我有一个 WeightCalculator 类:
Public Class WeightsCalculator
Public Sub New(...)
...
End Sub
Public Sub Calculate(ByVal entites As IList(Of IWeightable))
...
End Sub
End Class
按照流程:
- 实例化实体集合
Dim entites As New List(Of Entity) - 实例化权重计算器
Dim wc As New WeightsCalculator(...)
为什么我不能做 wc.Calculate(entities)?我收到:
无法转换类型的对象 'System.Collections.Generic.List
1[mynameSpace.Entity]' to type 'System.Collections.Generic.IList1[myNamespace.IWeightable]'。
如果实体实现了 IWeightable 为什么这不可能?
【问题讨论】:
标签: .net vb.net collections interface