golang copy 切片
package main import "fmt" type Test struct { A string } func main() { test1() test2() } func test1() { a := []int{1,2,3,4} var b []int b = make([]int, len(a)) copy(b, a) fmt.Println("b: ", b) } func test2() { a := []int{1,2,3,4} var b []int copy(b, a) fmt.Println("b: ", b) }
result;
b: [1 2 3 4]
b: []
邮箱: 1090055252@qq.com