-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.go
86 lines (78 loc) · 1.43 KB
/
map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
)
// func main(){
// var m map[string][]int
// m = make(map[string][]int)
// m["abdul"] = []int{122,23,4,5}
// m["aleem"] = []int{23,34,5}
// for k, v := range m {
// fmt.Println(k,v)
// }
// if k ,ok := m["abdul"]; ok{
// fmt.Println(k)
// }
// if k ,ok := m["saleem"]; ok{
// fmt.Println(k)
// }else{
// fmt.Println("no data")
// }
// delete(m, "abdul")
// for k, v := range m {
// fmt.Println(k,v)
// }
// employeesalary := map[string]int{
// "munna":23,
// "waseem":34,
// }
// for k, v := range employeesalary {
// fmt.Println(k,v)
// }
// }
//Lets create one string to struct map
type Employee struct {
salary int
country string
}
func main() {
emp1 := Employee{
200,
"india",
}
emp2 := Employee{
300,
"afghanistan",
}
emp3 := Employee{
400,
"indonesia",
}
m := map[string]Employee{
"Abdul": emp1,
"rashid khan": emp2,
"glane maxwell": emp3,
}
for k, v := range m {
fmt.Printf("Name: %s\n", k)
fmt.Printf("Salary: %d\n", v.salary)
fmt.Printf("Country: %s\n", v.country)
fmt.Println()
}
employeesalary := map[string]int{
"abdul": 2000,
"aleem": 3000,
"rashid": 3445,
}
m2 := employeesalary
m2["abdul"] = 34554
fmt.Println(employeesalary["abdul"])
delete(m2, "abdul")
fmt.Println(employeesalary["abdul"])
// comparing of two map
// if m2 == employeesalary{
// fmt.Println("true")
// }else{
// fmt.Println("false")
// }
}