0

I am trying to initialize an array of a structure which contains 2 variables inside.

Private Structure SnakeLocation
    Public Row As Integer
    Public Column As Integer
End Structure

I have tried the following, but neither work.

Private Position As SnakeLocation() = New SnakeLocation() With {.Row = 7, .Column = 8}
Private Position() As SnakeLocation = New SnakeLocation With {.Row = 7, .Column = 8}

How can I accomplish this?

1 Answer 1

1

You are close.

Dim Position As SnakeLocation() = New SnakeLocation() { new SnakeLocation With {.Row = 7, .Column = 8} }

First you create the array and initialize it with a SnakeLocation that is than initialized with the values.

Sign up to request clarification or add additional context in comments.

4 Comments

Interesting, is there a page I can view that explains how this works? Thank you for the answer by the way, I was stuck on this for a while.
Would this also be possible using a list? Something like this: Private Position1 As New List(Of SnakeLocation)(New SnakeLocation {.Row = 7, .Column = 8})
@Yezetee Yes, any collection with an Add function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.