From the course: Learning Go

Unlock this course with a free trial

Join today to access over 24,200 courses taught by industry experts.

Store ordered values in arrays

Store ordered values in arrays - Go Tutorial

From the course: Learning Go

Store ordered values in arrays

- [Instructor] Like other C-style languages, an array in Go is an ordered collection of values or references. I'll describe their basic features but also suggest right away that it's better to use slices than arrays to represent ordered collections of values. It's important though, to understand arrays before you get to slices. I'm starting in a fresh version of the main .go file in the practice directory and I'll create a new variable named colors. And I'll say that this is going to be an array of three strings. In Go you start with the number of items in the array wrapped in brackets and then the type of the values in the array. Now I can explicitly set each individual value like this. I'll say colors, open bracket, zero close bracket equals red. Now I'm going to make a couple copies of that line and I'll set colors one and two and the values to green and blue. Now I'll output that value by simply passing the array…

Contents