Go 语言中struct, slice , map 比较
2018-02-09 16:48
671 查看
package main import ( "fmt" "reflect" ) type testStruct struct { A int B string C []int } func main() { st1 := testStruct{A:100,B:"Australia",C:[]int{1,2,3}} st2 := testStruct{A:100,B:"Australia",C:[]int{1,2,3}} fmt.Println("Struct equal: ", reflect.DeepEqual(st1, st2)) slice1 := []int{1,2,3,4} slice2 := []int{1,2,3,4} fmt.Println("Slice equal: ", reflect.DeepEqual(slice1, slice2)) map1 := map[string]int{ "x":1, "y":2, } map2 := map[string]int{ "x":1, "y":2, "z":3, } fmt.Println("Map equal: ",reflect.DeepEqual(map1, map2)) }
编译输出:
C:/Go/bin/go.exe build -i [D:/golang/src/JsonTest] 成功: 进程退出代码 0. D:/golang/src/JsonTest/JsonTest.exe [D:/golang/src/JsonTest] Struct equal: true Slice equal: true Map equal: false 成功: 进程退出代码 0.
相关文章推荐
- 8.笔记go语言——复杂类型struct,slice,map
- go语言的 数组、slice、map使用(转)
- Go语言中的map和slice
- Go语言学习笔记(四) [array、slice、map]
- Go语言中的 Array, Slice和 Map
- Go语言学习笔记(四) [array、slice、map]
- 详解 Go 语言中 Map 类型和 Slice 类型的传递
- Go 语言中的 Array,Slice,Map 和 Set
- Go语言中的Array、Slice、Map和Set使用详解
- go语言的array,slice和map
- go语言学习-数组, slice和map
- 详解Go开发Struct转换成map两种方式比较
- [go语言]slice和map
- Go语言_array,slice,map
- Go语言基础:array、slice、make和new操作、map
- Go语言中的 Array, Slice和 Map
- 二、slice和数组的区别,map的注意事项 -go语言笔记
- Go语言 数组(Array), 分片(Slice), Map 以及 Set
- Go语言学习笔记(四) [array、slice、map]
- go 数组(array)、切片(slice)、map、结构体(struct)