go 数组

2018-02-28  本文已影响4人  seven_son

数组的定义:

    数组是指内存中连续空间内所保存的固定长度的数值。

数组的使用

1 先声明后赋值,在申明的同时要指定长度默认元素值为0

var colors [5]string 
colors=[5]string{"read","black","orange","whilte","green"}

2 声明同时创建

colors := [5]string{"read","black","orange","whilte","green"}

3 不指明长度,根据字面量系统指定长度

colors := [...]string{"read","black","orange","whilte","green"}

4 指定数组索引的某个值,未指定的默认为0

var colors [5]string 
colors=[5]string{3:"hello"}

数组的用途

colors := [...]string{"read","black","orange","whilte","green"}
colors[3]="blue"
上一篇下一篇

猜你喜欢

热点阅读