Files
XCSDD/docs/api/containers/array/operator-subscript.md
ssdfasd 58a83f445a fix: improve doc link navigation and tree display
- Fix link resolution with proper relative/absolute path handling
- Improve link styling with underline decoration
- Hide leaf nodes from tree, only show directories
- Fix log file path for packaged app
2026-03-19 12:44:08 +08:00

40 lines
953 B
Markdown

# Array::operator[]
```cpp
T& operator[](size_t index);
const T& operator[](size_t index) const;
```
按下标访问数组元素,不进行边界检查。
**行为:**
- 返回指定索引处元素的引用
- 不进行下标越界检查,性能最优
- 可用于读取和修改元素(非常量版本)
**参数:**
- `index` - 元素下标,从 0 开始
**返回:** 元素的引用(常量版本返回常量引用)
**复杂度:** O(1)
**线程安全:** ❌ 访问元素期间不可并发修改
**注意:** 不会进行边界检查。如果 `index >= Size()`,行为未定义。如需边界检查,请使用 `At()` 方法(如果存在)或自行检查。
**示例:**
```cpp
Containers::Array<int> arr = {10, 20, 30};
int first = arr[0]; // first == 10
int last = arr[2]; // last == 30
arr[1] = 25; // arr 现在是 {10, 25, 30}
```
## 相关文档
- [Array 总览](array.md) - 返回类总览