golang中“Type`的含义是什么?
发布时间:2020-12-16 09:29:50 所属栏目:大数据 来源:网络整理
导读:这段代码在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 allo
这段代码在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 main import "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类型的替身. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |