当我尝试在其中一个类文件中添加此属性时,我收到错误。
Friend Property StatusesCollection() As New Collection(Of Status)
此状态是属性集合。Status
中会抛出错误。
错误:
Microsoft.visualbasic.collection has no type parameters an so cannot have type arguments
答案 0 :(得分:2)
您的项目中有Microsoft.VisualBasic
的引用,其中包含Collection
类。这是编译器认为您尝试使用的内容并抛出您的错误,因为它不是泛型类型。
但是,您尝试使用的是Collection(Of T)
命名空间中的通用集合对象System.Collections.ObjectModel
。
最简单的解决方案是引用完全限定名称,以便该类不再含糊不清。变化:
Friend Property StatusesCollection() As New Collection(Of Status)
到
Friend Property StatusesCollection() As New System.Collections.ObjectModel.Collection(Of Status)
或者改为使用List(Of T)
:
Friend Property StatusesCollection() As New List(Of Status)
请参阅此问题进行比较:What is the difference between List (of T) and Collection(of T)?
答案 1 :(得分:0)
尝试添加此内容。
Imports System.Collections.ObjectModel