Dim lstNum As New List(Of Integer)(New Integer() { 3, 6, 7, 9 })
当我输入上述代码时,Visual Studio会告诉我有错误:
'Microsoft.Office.Interop.Word.List'没有类型参数,因此无法具有类型参数。 这是什么意思?如何解决?我无法创建任何类型的列表。我认为我缺少某种导入,但我的VB.Net水平不够流利,不知道该尝试什么。
Dim lstNum As New List(Of Integer)(New Integer() { 3, 6, 7, 9 })
使用 Generic.List 而不是仅使用 List。
Dim lstNum As New Generic.List(Of Integer)(New Integer() { 3, 6, 7, 9 })
既然您已经导入了Word interop,它正在尝试查找Word.List。指定Generic.List将告诉它走出这个导入范围。
尝试添加 System.Collections.Generic
Dim lstNum As New System.Collections.Generic.List(Of Integer)(New Integer() { 3, 6, 7, 9 })
你可以使用 Generic.list 代替 List,例如:Dim lstNum As New Generic.List(Of Integer)(New Integer() { 3, 6, 7, 9 })。或者你可以直接导入 System.Collections.Generic 命名空间。这两种方法都可以,但如果你需要反复使用 list,我建议选择后者。
Microsoft.Office.Interop.Word
。 - Kratz