Golang基础之关键字
Type
参考
##
https://blog.csdn.net/SHELLCODE_8BIT/article/details/122837699
type有如下几种用法:
- 定义结构体
- 定义接口
- 类型定义
- 类型别名
- 类型查询
类型定义
type Celsius float64 // 摄氏温度
type Fahrenheit float64 // 华氏温度
const (
AbsoluteZeroC Celsius = -273.15 // 绝对零度
FreezingC Celsius = 0 // 结冰点温度
BoilingC Celsius = 100 // 沸水温度
)
//
func CToF(c Celsius) Fahrenheit { return Fahrenheit(c*9/5 + 32) }
func FToC(f Fahrenheit) Celsius { return Celsius((f - 32) * 5 / 9) }