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

在Go中附加二维切片

I have a couple 2 dimensional slices in my Go program and I want to join them together.

However, append() doesn't take this type.

cannot use myArray (type [][]string) as type []string in append

How do you append multi-dimensional slices using Go in an idiomatic way?

Use ... to pass the second slice as variadic parameters to append. For example:

a := [][]string{{"a", "b"}, {"c", "d"}}
b := [][]string{{"1", "2"}, {"3", "4"}}
a = append(a, b...)

playground example

近期文章

  • 大型项目的包层次结构
  • 将请求中的json转换为golang中的数组
  • 在Go中正确使用os.NewFile
  • 如何在Go中有效处理大型数据数组(超过10MiB)?
  • golang-接口具有相同的方法,但被认为是不同的
  • Golang中的并发
  • 具有许多参数的构造函数
  • 如何访问模板中的结构字段
  • 解组XML注释
  • 在Linux上启动dev_appserver.py时出现“ getaddrinfo()参数1必须为字符串或None”错误
  • 为什么goroutine阻止此HTTP服务器中的main func?
  • 如何将参数传递给我的身份验证中间件以获取数据库访问权限
  • standard_init_linux.go:190:exec用户进程使用go basic Web应用程序导致“无此文件或目录” Docker
  • 通过迭代函数切片调用每个函数
  • 无法将字符串映射转换为json
  • 具有强制内容-md5的AWS S3预签名URL
  • 在Go中编写int32原子操作吗?
  • 在Go中使用没有文件的io.WriteSeeker
  • 网易新闻客户端viewpageer
  • 为什么要在init()中检查nil

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华