I'm using an array of class; the class is very simple and only contains one element. The class is declared as follows:
Class Cell
Public Info As Int16
End Class
The array:
Dim Maze(11, 15) As Cell
I want to use a simple sub to set the .Info variable for every element to 15, but I realise I have to create the elements first. I tried using a For Each loop as follows, but it didn't work, when the loop completed everything was still set to nothing:
For Each e As Cell In Maze
If e Is Nothing Then
e = New Cell
End If
Next
I'm not concerned about the correct solution: I used a regular For loop and this accomplishes everything I want done...
For a = 0 To Maze.GetUpperBound(0)
For b = 0 To Maze.GetUpperBound(1)
Maze(a, b) = New Cell
Maze(a, b).Info = Maze(a, b).Info Or 15
Next
Next
...but I'd like to know why the For Each loop didn't work in the first place, as I'm sure there's some fundamental principle I'm missing here.