go - 不能将 type chan []string) 用作 type []chan string?

标签 go channel goroutine

package main

import "fmt"

func x(foo []string, cz chan string) {
    for i := range foo {
        cz <- foo[i]
    }
}

func y(foo []string, cz chan string) {
    for i := range foo {
        cz <- foo[i]
    }
}

type cz struct {
    cSlice []chan string
}

func main() {

    var quality []string = make([]string, 2)
    quality[0] = "hello"
    quality[1] = "world"
    //name := []string{"mother", "earth"}

    var channel cz

    for i := range channel.cSlice {
        go x(quality, channel.cSlice[i])
        go y(quality, channel.cSlice[i])
        x, y := <-channel.cSlice[i], <-channel.cSlice[i]
        fmt.Println(x, y)
    }
}

现在什么都没有收到嗯...

更新^

...需要更多文字。

...然后再多一点。好的,还有多少?

我真的不敢相信。 fdsaf asf asfasdfdasfadfd

最佳答案

cannot use channel.cSlice (type chan []string) as type []chan string in argument to x
cannot use channel.cSlice (type chan []string) as type []chan string in argument to y

阅读错误信息。

输入chan []string

输入 []chan 字符串

它们是不同的。

Playground :https://play.golang.org/p/CKhj8DUGTle

关于go - 不能将 type chan []string) 用作 type []chan string?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54048930/

相关文章:

go - golang http.Get请求按常规方式工作,但在go例程内部不工作

go - 为什么这个 goroutine 不运行,即使是 `time.Sleep` ?

loops - 是否可以从外部功能停止股票行情/股票报价?

go - 如何让 goroutines 使用匿名函数在循环中返回值

go -/bin/sh : 1: gvm: not found

android - 打开YouTube channel 调用YouTube应用(Android)

go - Go 中的 Python 样式生成器

go - 如何在grpc go中实现非阻塞客户端?

io - 转到 channel 和 I/O

去 channel 无限循环