以下代码展示了用两种方法建立array。文章来源:https://www.toymoban.com/news/detail-683169.html
package main
import "fmt"
func main() {
var fruitList [4]string
fruitList[0] = "Apple"
fruitList[1] = "Tomato"
fruitList[3] = "Peach"
fmt.Println("Fruit list is: ", fruitList)
fmt.Println("The length of fruit list is: ", len(fruitList))
var vegList = [5]string{"potato", "beans", "mushroom"}
fmt.Println("Vegy list is: ", vegList)
fmt.Println("The length of vegy list is: ", len(vegList))
}
输出为:
Fruit list is: [Apple Tomato Peach]
The length of fruit list is: 4
Vegy list is: [potato beans mushroom ]
The length of vegy list is: 5文章来源地址https://www.toymoban.com/news/detail-683169.html
到了这里,关于Go 自学:Array阵列的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!