Programming/golang
golang 타입 캐스팅 제약(?)
구차니
2023. 11. 9. 10:58
눈에도 안들어 온다 으아아
[링크 : https://stackoverflow.com/questions/28040896/why-can-not-convert-sizebyte-to-string-in-go]
슬라이스를 배열로 하려면 copy 해야 하는 듯
package main import "fmt" //create main function to execute the program func main() { var slice []int // initialize slice slice = append(slice, 10) //fill the slice using append function slice = append(slice, 20) slice = append(slice, 30) // Convert the slice to an array array := [3]int{} //initialized an empty array copy(array[:], slice) //copy the elements of slice in newly created array fmt.Println("The slice is converted into array and printed as:") fmt.Println(array) // prints the output: [10 20 30] } |
[링크 : https://www.tutorialspoint.com/golang-program-to-convert-slice-into-array]