标签:func 遍历 关闭 pack color pac port for print
管道的关闭
package main func main() { var myChan chan int; myChan = make(chan int ,10); //添加管道 myChan <- 10; myChan <- 20; myChan <- 30; close(myChan);//关闭管道 }
管道遍历
package main import "fmt" func main() { var myChan chan int; len:=100; myChan = make(chan int ,len); //批量向管道添加数据 for i:=0;i <len;i ++{ myChan <- i; } close(myChan);//必须关闭i管道后才可以 for v:=range myChan { fmt.Println(v*2); } }
标签:func 遍历 关闭 pack color pac port for print
原文地址:https://www.cnblogs.com/zh718594493/p/14152903.html