package main
import (
"fmt"
)
func main() {
var chtest chan string
fmt.Println("no make:", chtest)
chtest = make(chan string, 10)
fmt.Println("make no value:", chtest)
chtest <- "one"
fmt.Println("value one:", chtest)
<-chtest
fmt.Println("out value:", chtest)
}
输出:
no make: <nil>
make no value: 0x1840d080
value one: 0x1840d080
out value: 0x1840d080
本文通过一个简单的Go语言程序示例,介绍了如何创建和使用通道(chan)。包括声明通道、使用make初始化通道、向通道发送数据及从通道接收数据的过程。

1943

被折叠的 条评论
为什么被折叠?



