为什么我不能像指定的 Go 引用那样将字符串附加到字节切片?

引自 Go的参考append


作为一种特殊情况,将字符串附加到字节切片是合法的,如下所示:

slice = append([]byte("hello "), "world"...)


但我发现我不能像这个片段那样做:


package main

import "fmt"


func main(){

    a := []byte("hello")

    s := "world"

    a = append(a, s) //*Error*: can't use s(type string) as type byte in append 

    fmt.Printf("%s",a)

}

我做错了什么?


慕的地10843
浏览 143回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go