为啥需要先var在make,make关键字能否稍微讲一下。我先** make([]chan int, 10)**为啥不行呢
func chanDemo() {
//var c chan int //c=nil,无法使用
var channels [10]chan int
//channels := make([]chan int, 10) //、为啥直接这么定义不行
for i := 0; i < 10; i++ {
channels[i] = make(chan int)
go worker(i, channels[i])
}
for i := 0; i < 10; i++ {
channels[i] <- 'a' + i
}
time.Sleep(time.Millisecond)
}