Created
September 15, 2014 10:54
-
-
Save reiki4040/a7b3126b85279722fbef to your computer and use it in GitHub Desktop.
example variable arguments for golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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