【发布时间】:2011-12-23 18:22:37
【问题描述】:
有没有方便的方法来初始化一个字节数组?
package main
import "fmt"
type T1 struct {
f1 [5]byte // I use fixed size here for file format or network packet format.
f2 int32
}
func main() {
t := T1{"abcde", 3}
// t:= T1{[5]byte{'a','b','c','d','e'}, 3} // work, but ugly
fmt.Println(t)
}
prog.go:8: 不能在字段值中使用“abcde”(类型字符串)作为类型 [5]uint8
如果我将行改为t := T1{[5]byte("abcde"), 3}
prog.go:8: 无法将“abcde”(类型字符串)转换为类型 [5]uint8
【问题讨论】:
标签: go