package main
import (
"fmt"
"strconv"
)
var c1 chan int
var c2 chan int
//var list = []*chan int{&c1, &c2}
var list = []chan int{c1, c2}
func main(){
c2 = make(chan int, 2)
c1 = make(chan int, 2)
//c2 <- 1
//c1 <- 2
for i := range list{
fmt.Println("---------" + strconv.Itoa(i))
list[i] = make(chan int, 3)
list[i] <- 2
//v = make(chan int, 3)
//v := list[i]
//v = make(chan int, 3)
//v <- 1
}
for _, v:= range list{
fmt.Printf("len:%d\n", len(v))
}
fmt.Println(len(c1))
fmt.Println(len(c2))
}
|
请发表评论