我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

切片内的阵列

is it possible to put a array within a slice? I tried [][2]int, but I can't figure out how to create an instance. The end result should be a mutable slice around an immutable 2 item array.

In python it would look like: [(1,2),(3,4)].

Go syntax uses {} braces for slices and arrays.

s := [][2]int{
    [2]int{1, 2},
    [2]int{3, 4},
}

But you can elide the inner types in the literal when they can be inferred:

s := [][2]int{{1, 2}, {3, 4}}
s = append(s, [2]int{5, 6})

近期文章

  • 如果条件在golang模板的范围内,则嵌套
  • Golang替代python / flask send_from_directory()
  • 在Go中修改结构中的结构切片
  • 如何平均JSON数组的值,然后舍入到小数点后1位
  • 当我们用另一个结构包装时,Gorm golang sql.NullInt64无法正常工作
  • Golang Godog REST API测试失败
  • 通过反射创建然后修改地图
  • 测试以检查功能是否未运行?
  • Gridview多表头如何加CSS样式呢
  • 如何正确地为此添加校验和标头?
  • 在golang中遍历结构而不反射
  • 前进:未加工的winsock
  • 函数是否可以更改在其他地方声明的字符串数组的大小? golang
  • 转到:是否可以将指针返回到函数
  • golang influxdb客户端对数组或切片的响应
  • 使用unsafe.Pointer时切片边界超出范围
  • GO Lang解码JSON(不提取简单数组)
  • 遍历端口列表以连接Golang
  • 对象Golang中的对象中的对象
  • mysql连接超时的最佳解决方案是什么?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华