golang中的switch

栏目: Go · 发布时间: 5年前

内容简介:执行结果:
func main(){
	arr := []interface{}{true,int16(1),uint8(2),"a",uint16(3),4,int8(5),"c",1.1}
	for _,v := range arr {
		fmt.Print(v)
		fmt.Print(" print type ")
		switch v.(type){
			case bool:
				fmt.Println("bool")
				continue
			case string:
				fmt.Println("string")
				break
			case uint8:
			case uint16:
				fmt.Println("uint")
			case int,int8,int16:
				fmt.Println("int")
			default:
				fmt.Println("default")
		}
	}
	fmt.Println("end")
}

执行结果:

true print type bool
1 print type int
2 print type a print type string
3 print type uint
4 print type int
5 print type int
c print type string
1.1 print type default
end

以上所述就是小编给大家介绍的《golang中的switch》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

免费

免费

[美] 克里斯·安德森 / 蒋旭峰、冯斌、璩静 / 中信出版社 / 2009-9 / 39.00

在《免费:商业的未来 》这本书,克里斯·安德森认为,新型的“免费”并不是一种左口袋出、右口袋进的营销策略,而是一种把货物和服务的成本压低到零的新型卓越能力。在上世纪“免费”是一种强有力的推销手段,而在21世纪它已经成为一种全新的经济模式。 究竟什么是免费商业模式?根据克里斯·安德森的说法,这种新型的“免费”商业模式是一种建立在以电脑字节为基础上的经济学,而非过去建立在物理原子基础上的经济学。......一起来看看 《免费》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换