切片作为地图中的关键 [英] Slice as a key in map
本文介绍了切片作为地图中的关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以尝试:
h:= map [[] string] string {
[] string {a,b}:ab,
}
编译器给我一个错误无效映射键类型[] string
。因此,要么是不可能的,要么是我宣布它不正确(如果是这样,那将是一个正确的方法?)。
Is it possible to use slices as keys?
There is my attempt:
h := map[[]string]string{
[]string{"a", "b"} : "ab",
}
the compiler gives me an error invalid map key type []string
. So either it's not possible or I declared it incorrectly (if so, what would be a correct way?).
解决方案
No, slices cannot be used as map keys as the have no equality defined.
这篇关于切片作为地图中的关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文