上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 44 下一页
摘要: package main import ( "fmt" "time" ) func testTime() { now := time.Now() fmt.Printf("current time: %v\n ", now) year := now.Year() month := now.Month( 阅读全文
posted @ 2022-03-12 18:30 ty1539 阅读(347) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "time" _ "time" "sync" ) /*需求:现在要计算 1-200 的各个数的阶乘,并且把各个数的阶乘放入到map中。 最后显示出来。要求使用goroutine完成 思路 1. 编写一个函数,来计算各个数的阶乘,并放入到 map 阅读全文
posted @ 2022-03-12 17:05 ty1539 阅读(279) 评论(0) 推荐(0) 编辑
摘要: 说明 map: 字典、映射 key———value key:唯一、无序。不能是引用类型数据。 map 不能便用cap() 创建方式: 1. var m1 map[int]string 不能存储数据 2. m2 := map[int]string 能存储数据 3. m3 := make(map[int 阅读全文
posted @ 2022-03-12 13:31 ty1539 阅读(378) 评论(0) 推荐(0) 编辑
摘要: package main import "fmt" func swap(a,b *int){ fmt.Printf("01>>&a=%p,&b=%p\n",a,b) a,b = b,a fmt.Printf("02>>&a=%p,&b=%p\n",a,b) fmt.Printf("03>>&a=%d 阅读全文
posted @ 2022-03-11 23:40 ty1539 阅读(56) 评论(0) 推荐(0) 编辑
摘要: 说明 为什么用切片: 1.数组的容量固定,不能自动拓展。 2.值传递。数组作为函数参数时,将整个数组值拷贝一份给形参。 在Go语言当,我们几乎可以在所有的场景中,使用切片替换数组使用。 切片的本质: 不是一个数组的指针,是一种数据结构体,用来操作数组内部元素。 runtime/slice.go ty 阅读全文
posted @ 2022-03-11 23:39 ty1539 阅读(45) 评论(0) 推荐(0) 编辑
摘要: package main import "fmt" func main() { var a int = 10 var p *int = &a fmt.Println( "000>>a = ",a) fmt.Printf( "000>>p=%v p=%v,&p=%p\n ",p,*p,p) a = 1 阅读全文
posted @ 2022-03-11 21:21 ty1539 阅读(50) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "math/rand" ) type Job struct { Number int Id int } type Result struct { job *Job sum int } func calc(job *Job, result cha 阅读全文
posted @ 2022-03-10 23:19 ty1539 阅读(162) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "time" ) func sendData(sendch chan<- int) { fmt.Println("go sendData", sendch) sendch <- 10 //<-sendch } func readData(sen 阅读全文
posted @ 2022-03-10 23:14 ty1539 阅读(18) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "runtime" "time" ) var i int func calc(i1 int) { for ;i < 10; i++ { // 死循环,不会自己结束的 //i ++ fmt.Printf("全局i:%d >>> 局部i1:%d g 阅读全文
posted @ 2022-03-10 23:13 ty1539 阅读(106) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "sync" "time" ) func process(i int, wg *sync.WaitGroup) { fmt.Println("started Goroutine ", i) time.Sleep(2 * time.Second) 阅读全文
posted @ 2022-03-10 22:03 ty1539 阅读(25) 评论(0) 推荐(0) 编辑
上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 44 下一页