本文實例講述了Go語言獲取數組長度的方法。分享給大家供大家參考。具體實現方法如下:
復制代碼代碼如下:
// getting the length of an array is silly, because the length is part of the array's static type
myArray := [3]int{1, 2, 3}
fmt.Println(len(myArray)) // prints 3
// getting the length of a slice
mySlice := []int{1, 2, 3}
fmt.Println(len(mySlice)) // prints 3
希望本文所述對大家的Go語言程序設計有所幫助。