使用结构对数组进行一行初始化

时间:2018-07-24 06:48:16

标签: vb.net

我正在尝试初始化内部包含2个变量的结构的数组。

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

我尝试了以下方法,但均无济于事。

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

我该怎么做?

1 个答案:

答案 0 :(得分:2)

你很近。

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

首先,创建数组并使用SnakeLocation对其进行初始化,然后使用值进行初始化。