Skip to content

Instantly share code, notes, and snippets.

@reiki4040
Created September 15, 2014 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reiki4040/a7b3126b85279722fbef to your computer and use it in GitHub Desktop.
Save reiki4040/a7b3126b85279722fbef to your computer and use it in GitHub Desktop.
example variable arguments for golang
package main
import (
"fmt"
)
func PrintStrings(strings ...string) {
for _, s := range strings {
fmt.Printf("%s", s)
}
fmt.Println()
}
func main() {
PrintStrings("a", "b", "c")
alphabet := []string{"a", "b", "c"}
// error 'cannot use alphabet (type []string) as type string in argument to PrintStrings'
// PrintStrings(alphabet)
PrintStrings(alphabet...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment