golang实现枚举类型
描述
golang无枚举类型, 但可以借助自定义类型实现
什么是枚举类型
枚举类型是一种类型, 它的值只有有限个. 换而言之, 枚举类型=一个类型+N个离散值
go的实现, 可以自定义一个类型, 把它作为枚举类型, 然后使用该类型定义N个常量.
示例
type FormatType int const ( FTByte FormatType = iota FTArray FTDefine ) func (ft FormatType) String() string { switch ft{ case FTByte: return "byte" case FTArray: return "array" case FTDefine: return "define" } return "" }
2023年8月09日 16:34
I can't wait to share this post with my colleagues. It's a goldmine of insights.
2023年10月22日 13:12
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. Thanks... ufabetทางเข้าเล่น
2023年11月15日 03:59
The kitchen is my sanctuary, where the magic of ingredients transforms into delightful dishes. It's a space where creativity and flavors collide, turning ordinary foods into extraordinary experiences.
2023年12月05日 01:41
https://darkweb.link/
2023年12月09日 21:19
I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job ! UFABETกติกาแทงบอล
2024年1月04日 14:46
WellSpa by Nu Skin is not your typical spa experience; it’s a holistic journey that aims to rejuvenate the body, mind, and spirit. Nestled in serene locations around the world, WellSpa offers a haven of tranquility, where cutting-edge science meets ancient relaxation techniques. Click here wellspa nuskin
2024年2月01日 13:04
Experience convenient and reliable transportation with our Taxi services in Walton on Thames. Whether you're heading to the airport or exploring the town, our dedicated team ensures a comfortable and prompt journey. Choose Taxi Walton on Thames for a seamless and stress-free travel experience.
2024年2月04日 18:59
Discover reliable and timely transportation with Taxi in Weybridge. Our service caters to your travel needs in and around Weybridge, offering prompt and comfortable rides. Choose Taxi in Weybridge for a stress-free journey, ensuring you reach your destination with ease and satisfaction.
2024年3月11日 05:07
Fashion is a form of self-expression that allows us to show the world who we are and what we stand for, without having to say a word. alchemai
2024年3月22日 19:00
I think you made some good points in Features also. Keep working, great job ! <a href="https://studioarash.com" rel="external">Wedding Photographers In Toronto</a>