這篇文章主要介紹了Go語(yǔ)言獲取數(shù)組長(zhǎng)度的方法,實(shí)例分析了len函數(shù)的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了Go語(yǔ)言獲取數(shù)組長(zhǎng)度的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
復(fù)制代碼代碼如下:
// 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
希望本文所述對(duì)大家的Go語(yǔ)言程序設(shè)計(jì)有所幫助。