[英]How to create an array of struct in golang as we create in C
我想在golang中創建一個struct
數組,就像我們在C中創建的那樣。我試圖像這樣創建,但是沒有用。
type State struct{
name string
population string
}st[5]
給出Struct
的定義
type State struct{
name string
population string
}
你有幾種方法。 您可以聲明一個包含5個State
的數組
var states [5]State
或者您可以在一行中指定(和自動聲明)
var states = [5]State{}
要么
states := State{}
您可能想從Go文檔開始。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.