func main() {
defer func() {
if p := recover(); p != nil {
fmt.Printf("Fatal error: %s\n", p)
}
}()
fmt.Println("Enter main")
outerFunc()
fmt.Println("Quit main")
}
defer func() {
if p := recover(); p != nil {
fmt.Printf("Fatal error: %s\n", p)
}
}()
fmt.Println("Enter main")
outerFunc()
fmt.Println("Quit main")
}
2021-01-14
func main() {
map1 := map[int]string{1: "Golang", 2: "Java", 3: "Python", 4: "C"}
sorted := [4]string{map1[1],map1[2],map1[3],map1[4]}
for i,v :=range sorted{
fmt.Printf("%d: %s\n",i+1,v)
}
}
map1 := map[int]string{1: "Golang", 2: "Java", 3: "Python", 4: "C"}
sorted := [4]string{map1[1],map1[2],map1[3],map1[4]}
for i,v :=range sorted{
fmt.Printf("%d: %s\n",i+1,v)
}
}
2021-01-14
func main() {
ia := []interface{}{byte(6), 'a', uint(10), int32(-4)}
switch v := ia[rand.Intn(4) ]; interface{}(v).(type) {
case interface{} :
fmt.Printf("Case A.")
case byte :
fmt.Printf("Case B.")
default:
fmt.Println("Unknown!")
}
}
ia := []interface{}{byte(6), 'a', uint(10), int32(-4)}
switch v := ia[rand.Intn(4) ]; interface{}(v).(type) {
case interface{} :
fmt.Printf("Case A.")
case byte :
fmt.Printf("Case B.")
default:
fmt.Println("Unknown!")
}
}
2021-01-14
type Dog struct {
Name_ string
Age_ uint8
}
func (d Dog)Name() string{
return d.Name_
}
func (d Dog)Age() uint8{
return d.Age_
}
Name_ string
Age_ uint8
}
func (d Dog)Name() string{
return d.Name_
}
func (d Dog)Age() uint8{
return d.Age_
}
2021-01-12
for i:=1;i<=(len(map1)+1);i++{
fmt.Println(i,":",map1[i])
}
这样不行吗
fmt.Println(i,":",map1[i])
}
这样不行吗
2020-09-21