Go Golang Stringer interface example implement String method

Publié le: 18 février 2018
sur la chaîne: OSPY
1,691
14

Go Golang Stringer interface example implement String method
package main

/* https://golang.org/pkg/fmt/ */
import (
"fmt"
)

/*A struct is a type which contains named fields.
Define new type named 'Person'*/
type Person struct {
Name string
Age int
Hobbies []string
}

/**Person type implements the method "String" of "Stringer" interface.*/
func (p Person) String() string {
return p.Name
}

func main() {

/*initialize a struct.
Create an instance of type 'Person'*/
p1 := Person{"Sam", 20, []string{"cricket", "football"}}
/*p1 := &Person{name: "Sam", age: 20, hobbies: []string{"cricket", "football"}}*/

fmt.Println("==p1==", p1)
}


Sur cette page du site, vous pouvez voir la vidéo en ligne Go Golang Stringer interface example implement String method durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur OSPY 18 février 2018, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 1,691 fois et il a aimé 14 téléspectateurs. Bon visionnage!