栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

进行锻炼,运动:切片索引超出范围

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

进行锻炼,运动:切片索引超出范围

切片

对于字符串,数组,指向数组的指针或切片a,主表达式

a [低:高]

构造一个子字符串或切片。索引表达式low和high选择哪些元素出现在结果中。结果的索引从0开始,长度等于高-低。

对于数组或字符串,索引low和high必须满足0 <= low <= high <= length;对于切片,上限是容量而不是长度。

指标

形式的主要表达

斧头]

表示由x索引的数组,切片,字符串或映射的元素。值x分别称为索引或映射键。适用以下规则:

对于类型A或* A(其中A是数组类型),或者对于类型S(其中S是切片类型):

x must be an integer value and 0 <= x < len(a)a[x] is the array element at index x and the type of a[x] isthe element type of Aif a is nil or if the index x is out of range, a run-time panic occurs

制作切片,地图和通道

make(T, n)       slice      slice of type T with length n and capacity nmake(T, n, m)    slice      slice of type T with length n and capacity m

y必须是整数值,并且0 <= y <len(pixel [] uint8)。x必须是整数值,并且0 <= x <len(pixel [] []
uint8)。例如,

package mainimport "tour/pic"func Pic(dx, dy int) [][]uint8 {    pixels := make([][]uint8, dy)    for y := 0; y < dy; y++ {        pixels[y] = make([]uint8, dx)        for x := 0; x < dx; x++ { pixels[y][x] = uint8(x * y)        }    }    return pixels}func main() {    pic.Show(Pic)}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/406496.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号