常量
Go语言支持的常量包括:字符、字符串、布尔值、数字值。
常量的声明:
const (
i int = 32 // int constant
s = "string" // string constant
i2 = 33 // untyped number constant
)
var (
// 非只读类型的值(如切片和映射)则不可以声明为常量
// 我们只能把它们声明为变量
b = []byte{3, 4} // 这不是一个常量
)
最后更新于
这有帮助吗?