Skip to content

Instantly share code, notes, and snippets.

@xvbnm48
Created March 8, 2022 15:04
Show Gist options
  • Save xvbnm48/85a95f0635219ee08c7d06f53fde6217 to your computer and use it in GitHub Desktop.
Save xvbnm48/85a95f0635219ee08c7d06f53fde6217 to your computer and use it in GitHub Desktop.
method pointer
package main
import "fmt"
type Gamer struct {
Name string
Games []string
}
func (game *Gamer) AddGame(nama string) {
game.Games = append(game.Games, nama)
}
func main() {
gamer := Gamer{Name: "Zelda"}
gamer.AddGame("Super Mario")
gamer.AddGame("Street Fighter")
gamer.AddGame("GTA")
for _, game := range gamer.Games {
fmt.Println(game)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment