Reputation: 3909
I want to create an array of struct
in golang as we create in C. I am trying to create like this, but is not working.
type State struct{
name string
population string
}st[5]
Upvotes: 3
Views: 2609
Reputation: 176342
Given a definition of a Struct
type State struct{
name string
population string
}
You have several ways. You can declare an array of 5 State
s
var states [5]State
Or you can assign (and autodeclare) in one line
var states = [5]State{}
or
states := State{}
You may want to start from the Go documentation.
Upvotes: 2