Created
March 8, 2022 15:04
-
-
Save xvbnm48/85a95f0635219ee08c7d06f53fde6217 to your computer and use it in GitHub Desktop.
method pointer
This file contains hidden or 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" | |
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