Files
the-way-to-go_ZH_CN/eBook/examples/chapter_10/method2.go
2015-03-03 12:25:25 -05:00

17 lines
216 B
Go

package main
import "fmt"
type IntVector []int
func (v IntVector) Sum() (s int) {
for _, x := range v {
s += x
}
return
}
func main() {
fmt.Println(IntVector{1, 2, 3}.Sum()) // Output: 6
}