Golang常量iota的使用实例-创新互联

Codes

桓台网站建设公司创新互联建站,桓台网站设计制作,有大型网站制作公司丰富经验。已为桓台上千余家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的桓台做网站的公司定做!
package main
import "fmt"
type color byte
const (
  black color = iota
  red
  blue
)
func test(c color) {
  fmt.Println(c)
}
func main() {
  const (
    x = iota // 0
    y    // 1
    z    // 2
  )
  fmt.Printf("x=%v, y=%v, z=%v\n", x, y, z)
  const (
    _ = iota
    KB = 1 << (10 * iota) // 1 << (10 * 1)
    MB          // 1 << (10 * 2)
    GB          // 1 << (10 * 3)
  )
  fmt.Printf("KB=%v, MB=%v, GB=%v\n", KB, MB, GB)
  const (
    _, _  = iota, iota * 10 // 0, 0 * 10
    aa, bb          // 1, 1 * 10
    cc, dd          // 2, 2 * 10
  )
  fmt.Printf("aa=%v, bb=%v, cc=%v, dd=%v\n", aa, bb, cc, dd)
  const (
    a = iota // 0
    b    // 1
    c = 100 // 100
    d    // 100
    e = iota // 4
    f    // 5
  )
  fmt.Printf("a=%v, b=%v, c=%v, d=%v, e=%v, f=%v\n", a, b, c, d, e, f)
  const (
    g     = iota // 0
    h float32 = iota // 1
    i     = iota // 2
  )
  fmt.Printf("g: %T %v, f: %T %v, h: %T %v\n", g, g, h, h, i, i)
  test(black) // 0
  test(red)  // 1
  test(blue) // 2
  test(100)  // 100 并未超出 color/byte 类型取值范围
  // xx := 2
  // test(xx)
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:Golang常量iota的使用实例-创新互联
网站URL:http://myzitong.com/article/dseedd.html