久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      golang iota從幾開始

      golang iota從幾開始

      iota是golang語言的常量計(jì)數(shù)器,只能在常量的表達(dá)式中使用。

      iota在const關(guān)鍵字出現(xiàn)時(shí)將被重置為0(const內(nèi)部的第一行之前),const中每新增一行常量聲明將使iota計(jì)數(shù)一次(iota可理解為const語句塊中的行索引)。 (推薦學(xué)習(xí):go)

      使用iota能簡化定義,在定義枚舉時(shí)很有用。

      在常量定義中,iota可以方便的迭代一個(gè)值從0以步長1遞增,0,1,2,3,4,5…

      本例以文件大小的格式2的10次方進(jìn)位一次為依據(jù),將KB為1左移10位,MB左移20位。。。

      本文中的Sprintf(“%f”,x)并不會(huì)因?yàn)槎x在String方法內(nèi)而引起無窮循環(huán)bug,因?yàn)?f不會(huì)去嘗試調(diào)用String()

      package main import (     "fmt" ) type ByteSize float64 const (     _ = iota     KB ByteSize = 1 << (10*iota)     MB     GB     TB     PB     EB     ZB     YB ) func (b ByteSize) String() string{     switch {         case b >= YB:             return fmt.Sprintf("%.2fYB",b/YB)         case b >= ZB:             return fmt.Sprintf("%.2fZB",b/ZB)         case b >= EB:             return fmt.Sprintf("%.2fEB",b/EB)         case b >= PB:             return fmt.Sprintf("%.2fPB",b/PB)         case b >= TB:             return fmt.Sprintf("%.2fTB",b/TB)         case b >= GB:             return fmt.Sprintf("%.2fGB",b/GB)         case b >= MB:             return fmt.Sprintf("%.2fMB",b/MB)         case b >= KB:             return fmt.Sprintf("%.2fKB",b/KB)      }     return fmt.Sprintf("%.2fB",b) }  func main() {     fmt.Println(ByteSize(1e10)) }

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號