2017-11-04 12:36
浏览 546


While declaring an array or a slice I'm required to specify the type of data that I want to store in the array or list.

How do I make an array that can hold data of multiple types ?

图片转代码服务由CSDN问答提供 功能建议

在声明数组或切片时,我需要指定数据的类型 我要存储在数组或列表中的数据。

如何制作一个可以容纳多种类型数据的数组? < / DIV>

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongmu3457 2017-11-04 12:39

    You can do something like this mixedArray := []interface{}{"astring", 10, &Object{'hello'}}

    Most likely the values that you want to hold share some behavior, in that case what you should really do is create an interface and simply make the array content type that interface.

    打赏 评论

相关推荐 更多相似问题