package main
import (
"fmt"
)
type Student struct {
Id string
Name string
Age int
Score float64
}
func (this Student) ToString() string {
return fmt.Sprintf("id: %s\nName: %s\nAge: %d\nScore: %0.1f", this.Id, this.Name, this.Age, this.Score)
}
func main() {
student := Student{
Id: "st01",
Name: "Name 1",
Age: 20,
Score: 5.6,
}
fmt.Println(student.ToString())
}
Output
id: st01
Name: Name 1
Age: 20
Score: 5.6