Obtain array from slice in Go (language)
If I create a slice with (e.g.)
mySlice := make([]int, 5, 10)
then I suppose an array of type [10]int is created silently, and I receive
a slice that "sees" the first 5 ints.
(Right? The Go docs don't quite phrase it this way, but since a slice must
always have an underlying array somewhere, I don't see how it could be any
other way.)
So I believe the above is shorthand for:
var myArray [10]int
mySlice := myArray[0:5]
But when I use the first method, I don't have a handle to the array. Is
there any way to obtain it from the slice?
No comments:
Post a Comment