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

make([] string)和[] string {}有什么区别

I make global declaration of a value.

var {
     b = make([]string,10)  //way 1
     a = []string{}         //way 2
}

Both ways work. Can someone make detailed explanation of the difference between them?

The expression make([]string,10) returns a slice with length and capacity of 10. The expression []string{} returns a slice with length and capacity of 0.

Check it out on the playground.

近期文章

  • 如何检测/处理多种unicode方式来对字母上的重音进行编码
  • Gomobile软件包中没有导出的名称
  • 在go中使用new和channel
  • 无限期运行Go例程
  • go-mysql:从go应用程序容器连接到mysql容器时,不支持身份验证插件
  • 使用gRPC在容器之间进行通信
  • 在Golang中测试文件系统的示例代码
  • 具有并发读取器的Golang缓冲区
  • Hugo如何维护站点范围内的数据,例如.Site.AllPages?
  • 去测试`-parallel`与`-test.parallel`哪个标志优先?
  • 使用for循环打印给定的字符模式?
  • 解释Golang错误代码
  • 更改结构值
  • 如何编写mbox格式的文件?
  • 将go.rice与http.ServeFile()一起使用
  • 删除边框/裁剪图像的最佳方法
  • go-使用值作为列表创建字典[重复]
  • 运行时错误:无效的内存地址或公共指针中的nil指针取消引用
  • 在Go中编写文本SQL查询的正确方法
  • 如何将结构编码回字节缓冲区

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华