Let's say I have a struct
type Rectangle struct {
length, width int
}
and I want to add a method to it:
func (r Rectangle) Area() int {
return r.length * r.width
}
Why must I give it a variable name here r?
Let's say I have a struct
type Rectangle struct {
length, width int
}
and I want to add a method to it:
func (r Rectangle) Area() int {
return r.length * r.width
}
Why must I give it a variable name here r?