2020
12-24
12-24
go 判断两个 slice/struct/map 是否相等的实例
可以通过reflect.DeepEqual比较两个slice/struct/map是否相等:packagemainimport("fmt""reflect")typeAstruct{sstring}funcmain(){a1:=A{s:"abc"}a2:=A{s:"abc"}ifreflect.DeepEqual(a1,a2){fmt.Println(a1,"==",a2)}b1:=[]int{1,2}b2:=[]int{1,2}ifreflect.DeepEqual(b1,b2){fmt.Println(b1,"==",b2)}c1:=map[string]int{"a":1,"b":2}c2:=map[string]int{"a":1...
继续阅读 >