<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ``` ~~~ package main import ( "encoding/json" "fmt" "time" ) type Sender = chan <- int //只寫通道類型 type Receiver = <- chan int //只讀通道類型 func testChan4(mychan chan int) { n := cap(mychan) x, y := 1, 1 for i := 0; i < n; i++ { mychan <- x x, y = y, x+y } close(mychan) } func main() { // 信道遍歷 testchan4 := make(chan int, 10) go testChan4(testchan4) for x := range testchan4 { fmt.Println("testchan4 信道值:", x) } // 單向信道 var testchan3 = make(chan int) go func() { var sender Sender = testchan3 fmt.Println("準備發送數據: 100") sender <- 100 }() go func() { var receiver Receiver = testchan3 num := <- receiver fmt.Println("接收到的數據是", num) }() time.Sleep(time.Second) // 雙向信道 testchan2 := make(chan int) go func() { fmt.Println("準備發送數據:100") testchan2 <- 100 }() go func() { num := <- testchan2 fmt.Println("接收到的數據", num) }() time.Sleep(time.Second) // 信道 testchan := make(chan int, 10) //第二個參數大于0時,為緩沖信道,發送端和接收端可以處于異步狀態; 為0則為無緩沖信道, 發送端和接收端為同步 fmt.Println("testchan 信道可緩沖數據量", cap(testchan)) testchan<- 1 fmt.Println("testchan 信道當前數據量", len(testchan)) x, ok := <-testchan //從信道中讀取數據, x為數據; ok為信道是否關閉, 弱沒有關閉, ok為true fmt.Println("testchan 信道數據:", x) if ok { close(testchan) } // 協程 go mygo("協程1號") go mygo("協程2號") time.Sleep(time.Second) // 空接口 var i interface{} // 使用 1 i = 1 fmt.Println(i) i = "hello" fmt.Println(i) i = false fmt.Println(i) // 使用 2 myInterface(1) myInterface("hello") myInterface(false) // 使用 3 myInterfaceList(1, "hello", false) // 類型斷言 var i1 interface{} = 10 t1 := i1.(int) fmt.Println(t1) t2, ok := i1.(string) fmt.Println(t2, ok) // Tag p1 := People{ Name: "張三", Age: "18", } people1, err := json.Marshal(p1) if err != nil { fmt.Println(err.Error()) } fmt.Printf("%s\n", people1) p2 := People{ Name: "李四", Age: "18", Sex: "男", } people2, err := json.Marshal(p2) if err != nil { fmt.Println(err.Error()) } fmt.Printf("%s\n", people2) // interface, 多態 apple := Apple{ name: "蘋果", quantity: 2, price: 10, } pear := Pear{ name: "梨", quantity: 3, price: 9, } goods := []Good{apple, pear} price := formatOrderInfo(goods) fmt.Println("訂單總金額:", price) // 繼承 company := company{ companyName: "騰訊", companyAddress: "深圳", } staff := staff{ name: "張三", age: 29, sex: "男", company: company, } fmt.Println(staff.name, "在", staff.companyName, "工作") fmt.Println(staff.name, "在", staff.company.companyName, "工作") //結構體 persion := Person{ name: "張三", age: 18, sex: "男", } persion.FmtPerson() persion.nextAge() persion.FmtPerson() // 變量命名方法 //第一種: 一行生命一個變量 // var <name> <type> var name1 string = "hello world" fmt.Println(name1) //第二種: 聲明多個變量 var ( name2 string = "張三" age int32 = 28 gender string = "男" ) fmt.Println(name2, age, gender) //第三種: 聲明和初始化一個變量 name3 := "李四" fmt.Println(name3) //第四種: 聲明和初始化多個變量 name4, age4 := "王五", 30 fmt.Println(name4, age4) //第五種: new函數聲明一個指針變量 var age5 int32 = 31 var age6 = &age5 //&后面變量名, 表示取出該變量的內存地址 fmt.Println("age5", age5, "age6", age6) // goto /* goto flag fmt.Println("A") flag: fmt.Println("B") */ } ~~~ ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看