Add type methods

This commit is contained in:
Ayke van Laethem
2018-04-16 17:04:49 +02:00
parent 139ac45cb1
commit 013b375904
2 changed files with 37 additions and 11 deletions
+5 -1
View File
@@ -5,6 +5,10 @@ type Thing struct {
name string
}
func (t Thing) String() string {
return t.name
}
const SIX = 6
func main() {
@@ -16,7 +20,7 @@ func main() {
println("sumrange(100) =", sumrange(100))
thing := Thing{"foo"}
println("thing:", thing.name)
println("thing:", thing.String())
}
func calculateAnswer() int {