英文:
How can I represent map[string][]byte?
问题
我想创建一个地图,但我不确定语法。map[string][]byte
数据类型给我带来了麻烦,因为我认为下面的示例应该是编译器所期望的样子,但我收到了一个错误消息,对于正确的表示方式并不清楚。
map["k1":[1,2,3] "k2":[4,5,6] "k3":[7,8,9]]
错误消息:
> 期望的类型,找到了 "k1"
我该如何修复语法?
英文:
I would like to create a map, but I am unsure of the syntax. The map[string][]byte
data type is giving me trouble, because I think that the example below should be what it should look like in order to appease the compiler, but I receive an error which is unclear about how it should be properly depicted.
map["k1":[1,2,3] "k2":[4,5,6] "k3":[7,8,9]]
The error message:
> expected type, found "k1"
How can I fix the syntax?
答案1
得分: 2
你的语法有问题。
你应该像下面这样初始化和声明:
x := map[string][]byte{
"k1": []byte{1, 2, 3},
"k2": []byte{4, 5, 6},
"k3": []byte{7, 8, 9},
}
英文:
You have bad syntax.
You should initialize it and declare like below
x := map[string][]byte{
"k1": []byte{1, 2, 3},
"k2": []byte{4, 5, 6},
"k3": []byte{7, 8, 9},
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论