Structs
type Person struct {
Name string
Age int
}
var p Person
p.Name = "John Doe"
p.Age = 42
fmt.Println(p)
fmt.Printf("Name: %s, Age: %d\n", p.Name, p.Age)type Rectangle struct {
width float64
height float64
}
func (r Rectangle) area() float64 {
return r.width * r.height
}
r := Rectangle{width: 3.0, height: 4.0}
fmt.Println(r.area())Sorular
Last updated