interface IDataElement
property Name as string
property Value as object
end interface
public class DataElementSet(Of T as IDataElement)
implements IList(Of T)
...
end class
public Class A
implements IDataElement
...
end class
public Class ACollection
Inherits DataElement(Of A)
...
end class
问题:
Shared sub Test
dim ac as new ACollection,objA as new A
console.writeline(TypeOf objA is IDataElement)
'返回True
console.writeline(TypeOf ac is IList(of IDataElement))
'返回false
console.writeline(TypeOf ac is IList(Of A))
'返回True
end sub
请教高手:A已经执行了IDataElement接口,按理来说ac即具备IList(Of IDataElement)接口,也具备IList(Of A)的接口。为什么第二个命令会返回False?
A实现了IDataElement
不等于
List<A>从List<IDataElement>派生。
如果DataElementSet是接口,并且是VB11以上,可以修饰为逆变接口,但是DataElementSet如果是类,那无能为力。
不过你可以通过Linq的Select操作转换下