What is the difference between []string and …string in golang?

前端 未结 4 492
醉话见心
醉话见心 2021-01-30 09:44

In the Go language,

[]string is a string array

and we also use ...string as a parameter.

What is the difference?

Functi

4条回答
  •  有刺的猬
    2021-01-30 10:30

    Here is what you want:

    var args []string = []string{"A", "B", "C"}
    
    func Sample(args ...string) {
        for _, arg := range args {
            fmt.Println(arg)
        }
    }
    
    func main() {
        Sample(args...)
    }
    

    Play: http://play.golang.org/p/N1ciDUKfG1

提交回复
热议问题