golang中“Type`的含义是什么?

golang中“Type`的含义是什么?,第1张

概述这段代码在builti.go中 // The append built-in function appends elements to the end of a slice. If// it has sufficient capacity, the destination is resliced to accommodate the// new elements. If it does not 这段代码在builti.go中

// The append built-in function appends elements to the end of a slice. If// it has sufficIEnt capacity,the destination is resliced to accommodate the// new elements. If it does not,a new underlying array will be allocated.// Append returns the updated slice. It is therefore necessary to store the// result of append,often in the variable holding the slice itself://  slice = append(slice,elem1,elem2)//  slice = append(slice,anotherSlice...)// As a special case,it is legal to append a string to a byte slice,like this://  slice = append([]byte("hello "),"world"...)func append(slice []Type,elems ...Type) []Type

最后一行让我感到非常困惑.我不知道有关……的意思.

这是其他代码.

package mainimport "fmt"func main() {   s := []int{1,2,3,4,5}   s1 := s[:2]   s2 := s[2:]   s3 := append(s1,s2...)   fmt.Println(s1,s2,s3)

}

结果是

[1 2] [3 4 5] [1 2 3 4 5]

我想关于…的功能是从elems中选择所有元素.

我找不到官方的解释

解决方法 builtin.go中的代码用作文档.代码未编译.

…指定函数的最终参数是可变参数.变量参数是documented in the Go Language specification.

Type部分是任何Go类型的替身.

总结

以上是内存溢出为你收集整理的golang中“Type`的含义是什么?全部内容,希望文章能够帮你解决golang中“Type`的含义是什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1268390.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存