package main
import (
"container/list"
"fmt"
)
func maptest() {
var maptest = make(map[string]int)
maptest["shunfeng"]=1
maptest["dath"]=2
maptest["qige"]=3
fmt.Println(maptest)
delete(maptest,"dath")
fmt.Println(maptest)
}
func listtest() {
var listtests = list.New()
listtests.PushBack("darg")
listtests.PushFront("list")
for i:=listtests.Front();i!=nil;i=i.Next(){
fmt.Println(i.Value)
}
}
func main() {
maptest()
listtest()
}
package main
import "fmt"
//自定义类型chip 第一个默认为chip 后续常量未复制情况下继承chip的值和chip的关联方法
type chip int
const (
none chip = iota
CPU
GPU
)
func (c chip) string() string {
switch c {
case none:
return "None"
case CPU:
return "cpu"
case GPU:
return "GPU"
}
return "N/A"
}
func main() {
fmt.Printf("%s %d",CPU.string(),CPU)
}
go-映射-列表-常量用例
最新推荐文章于 2024-05-22 12:25:23 发布