← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6074.c.8 · 生成模型:未记录

数组长度进入类型

理解等级:中级

[T; N] 表示固定个数的同类型元素,例如月份表。动态索引达到或超过长度时,方括号访问会触发 panic,避免继续读写无效地址。外部下标需要可恢复行为时,可先检查边界或使用返回 Option 的查询。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第03章 常见编程概念(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c03.xhtml`,块 0133) - 结论依据:书中用 [i32; 5] 把元素类型与个数一起写在类型中。 - 原始内容:You write an array’s type using square brackets with the type of each element, a semicolon, and then the number of elements in the array, like so: