Member Avatar for Chris11246

Im making a sim of a robocup for a project and it would really help make the code easier to read if I could have an array of players but I cant dim and array as new and my players are all a class I made called gameobject.
How do I make an array of players as my class gameobject?

Dim i As Integer = -1
        i += 1
        ReDim Preserve MyPlayers(i)
        MyPlayers(i) = TextBox1.Text
Member Avatar for Chris11246

thats not the problem I wanted to know if there was a way to dim an array as a class like:
Dim players(9) as new gameobject
but you cant dim one as new and if i just do:
Dim players(9) as new gameobject
it says "object reference not set to an instance of an object"

you need to initialize each player as new gameobject

Dim players(9) As gameobject
        For i As Integer = 0 To players.Length - 1
            players(i) = New gameobject
            players(i).testProperty = CStr(i)
        Next

        For i As Integer = 0 To players.Length - 1
            Console.WriteLine(players(i).testProperty)
        Next
Member Avatar for Chris11246

ok thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.