我一直在阅读 [golang-book]:http ://www.golang-book.com并在进行过程中完成练习。在第 6 章中,有一个练习必须找到未排序列表 [x] 中的最小元素。
我有以下代码,但不知何故我不知道为什么方法长度 (len) 在第 14 行给我一个错误:x.len undefined (type []int has no field or method len)
package main
import "fmt"
func main() {
x := []int{
48, 96, 86, 68,
57, 82, 63, 70,
37, 34, 83, 27,
19, 97, 9, 17,
}
small := x[0]
for i := 1; i < x.len(); i++ {
if x[i] < small {
fmt.Println(x[i])
}
}
}
我使用的逻辑是用谷歌搜索的,所以数组上可能没有 len 方法?任何帮助是极大的赞赏。