redhotspike
redhotspike

Reputation: 1096

Can't declare lists in VB.NET?

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

When I type the above line of code, Visual Studio informs me of an error

'Microsoft.Office.Interop.Word.List' has no type parameters and so cannot have type arguments.

What on earth does that mean and how do I fix it? I can't seem to create lists of any kind. I'm assuming I'm missing some sort of import but I'm not fluent with VB.Net enough to know what to try.

Upvotes: 5

Views: 21100

Answers (3)

Hassan
Hassan

Reputation: 118

Either You use Generic.list instead of List Dim lstNum As New Generic.List(Of Integer)(New Integer() { 3, 6, 7, 9 }) Or you just import System.Collections.Generic Namespace, Both approaches are fine, but I'd go for the later one if I've to use list again and again. .

Upvotes: 0

Emmanuel N
Emmanuel N

Reputation: 7449

Try adding System.Collections.Generic

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

Upvotes: 6

David Brunow
David Brunow

Reputation: 1299

Use Generic.List instead of just List.

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

Since you have the Word interop imported, it is trying to find Word.List. Specifying Generic.List will tell it to go outside of that import.

Upvotes: 8

Related Questions