2
1
Fork 0
pr3-ws202526/go/02-next-level/00-methods.go

25 lines
315 B
Go

package main
import "fmt"
type Counter struct {
value int
}
// pointer receiver
func (c *Counter) Increment() {
c.value++
}
// value receiver
func (c Counter) String() string {
return fmt.Sprintf("Counter value: %d", c.value)
}
func main() {
c := Counter{}
fmt.Println(c)
c.Increment()
fmt.Println(c)
}