I am aware that I can’t dynamically refer to a variable (eg. ‘var & var.Close()’).
Can I somehow have a variable that can point to another variable by name?
My current code is (where func() requires an array):
Dim playerNum As String = “P1”
Select Case playerNum
Case “P1”
Func(P1(x, xx))
Case “P2”
Func(P2(x, xx))
.........
End Select
Can something along these lines be done?
Dim playerNum As varNameRef = P1(,)
Func(playerNum(x, xx))
Really anything to stop so much repetition would be greatly appreciated.
Cheers.
What you need is a reference type (class), instead of a value type (structure). For instance, if you created a class that stored your array as a property, like this:
This also gives you the advantage of easily expanding the data that you store about each player. Then, you could reference the same
PlayerDataobject with multiple variables:However, it would be even better yet to store them in a dictionary as key value pairs, such as:
Then, you could access you players like this: