繁体   English   中英

如何在我们用C创建的golang中创建一个struct数组

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM