Edit

Share via


BC32039: Array declared as for loop control variable cannot be declared with an initial size

A For Each loop uses an array as its iteration variable but initializes that array.

Error ID: BC32039

Example

The following example generates bc32039:

Dim arrayList As New List(Of Integer())
For Each listElement(1) As Integer In arrayList

Next

To correct this error

Remove the initialization from the declaration of the iteration variable as shown in the following example:

Dim arrayList As New List(Of Integer())
For Each listElement() As Integer In arrayList

Next

or you can use type inference:

Dim arrayList As New List(Of Integer())
For Each listElement In arrayList

Next

See also