gpt4 book ai didi

go - slice 中的长度和容量方法

转载 作者:数据小太阳 更新时间:2023-10-29 03:44:03 26 4
gpt4 key购买 nike

<分区>

Reading关于 Golang 中的数组和 slice 。

为什么使用 lencap 等内置函数,而不是 slice 对象上的类似方法?

if cap(slice) == len(slice) {
fmt.Println("slice is full!")
}

对比

if slice.cap() == slice.len() {
fmt.Println("slice is full!")
}

为什么要污染全局命名空间?为什么不使用面向对象的风格?

另外,是否存在这样的方法,是否可以使用它们代替内置函数?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com