How to convert slice to fixed size array? [duplicate]
问题 This question already has answers here : How do you convert a slice into an array? (5 answers) Closed 22 days ago . I want to convert a fixed size array from a slice: func gen(bricks []Brick) { if len(bricks) == 16 { if check(Sculpture{bricks}) { var b [16]Brick = bricks[0:16]; } } } But this results in: cannot use bricks[0:16] (type []Brick) as type [16]Brick in assignment How to convert a slice into a fixed size array? 回答1: You need to use copy : slice := []byte("abcdefgh") var arr [4]byte