Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';在VB.NET中不声明列表?_Vb.net - Fatal编程技术网

Can';在VB.NET中不声明列表?

Can';在VB.NET中不声明列表?,vb.net,Vb.net,当我键入上述代码行时,VisualStudio会通知我一个错误 “Microsoft.Office.Interop.Word.List”没有类型参数,因此不能有类型参数 这到底意味着什么?我该如何修复它?我似乎无法创建任何类型的列表。我假设我缺少某种导入,但我对VB.Net不够流利,不知道该尝试什么。使用Generic.List而不仅仅是List Dim lstNum As New List(Of Integer)(New Integer() { 3, 6, 7, 9 }) 由于已导入单词in

当我键入上述代码行时,VisualStudio会通知我一个错误

“Microsoft.Office.Interop.Word.List”没有类型参数,因此不能有类型参数


这到底意味着什么?我该如何修复它?我似乎无法创建任何类型的列表。我假设我缺少某种导入,但我对VB.Net不够流利,不知道该尝试什么。

使用Generic.List而不仅仅是List

Dim lstNum As New List(Of Integer)(New Integer() { 3, 6, 7, 9 })

由于已导入单词interop,因此它正在尝试查找Word.List。指定Generic.List将告诉它超出导入范围。

尝试添加
System.Collections.Generic

Dim lstNum As New Generic.List(Of Integer)(New Integer() { 3, 6, 7, 9 })

要么使用Generic.list而不是list Dim lstNum作为新的Generic.list(of Integer)(New Integer(){3,6,7,9}),要么只导入System.Collections.Generic命名空间,这两种方法都可以,但如果我不得不反复使用list,我会选择后一种方法

您没有丢失导入,似乎您为Microsoft.Office.Interop.Word有一个额外的导入,我没有声明任何导入;也许因为我没有导入,它选择了它在列表中找到的第一个导入-Microsoft在导入列表中位于系统之前…顺便说一句,我打赌你“确实声明了导入”,但没有意识到,因为“声明”在你的VB项目的属性、引用选项卡、“导入的命名空间”中。这适用于项目中的所有.vb文件。(我提到这一点,以防将来的读者不知道他们应该去那里看。)去那里,取消选中Microsoft…Word。然后只将Word添加到需要它的文件中。谢谢!就这样!(这让我等了11分钟才接受,但这将被接受)更具体地说,请确保您正在导入System.Collections.Generic命名空间并/或为其添加别名。除非他导入了System.Collections,否则Generic.List不一定有效。不确定具体情况,但我不必导入System.Collections.Generic。可能是因为我在使用ASP.NET?
 Dim lstNum As New System.Collections.Generic.List(Of Integer)(New Integer() { 3, 6, 7, 9 })