mas ejemplos

This commit is contained in:
2021-09-13 18:03:16 +00:00
parent bf872f0919
commit 5160e2ae78
5 changed files with 187 additions and 0 deletions

26
gobyexample/methods.go Normal file
View File

@ -0,0 +1,26 @@
package main
import "fmt"
type rect struct {
width, height int
}
func (r *rect) area() int {
return r.width * r.height
}
func (r rect) perim() int {
return 2*r.width + 2*r.height
}
func main() {
r := rect{width: 10, height: 5}
fmt.Println("area:", r.area())
fmt.Println("perim:", r.perim())
rp := &r
fmt.Println("area:", rp.area())
fmt.Println("perim:", rp.perim())
}