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》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

精通正则表达式

精通正则表达式

Jeffrey E. F. Friedl / 余晟 / 电子工业出版社 / 2007 / 75

随着互联网的迅速发展,几乎所有工具软件和程序语言都支持的正则表达式也变得越来越强大和易于使用。本书是讲解正则表达式的经典之作。本书主要讲解了正则表达式的特性和流派、匹配原理、优化原则、实用诀窍以及调校措施,并详细介绍了正则表达式在Perl、Java、.NET、PHP中的用法。 本书自第1 版开始着力于教会读者“以正则表达式来思考”,来让读者真正“精通”正则表达式。该版对PHP的相关内容、Ja......一起来看看 《精通正则表达式》 这本书的介绍吧!

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

在线压缩/解压 CSS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具