The Go language method to get the length of an array

  • 2020-05-24 05:41:57
  • OfStack

This example shows how the Go language gets the length of an array. Share with you for your reference. The specific implementation method is as follows:

// 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

I hope this article has been helpful to your programming of Go language.


Related articles: