Christian-health / go-learn

0 stars 0 forks source link

goLang 视频讲解 #39

Open Christian-health opened 5 years ago

Christian-health commented 5 years ago
package main

import (
    "fmt"
    "sort"
)

func test_sort()  {
    yang := [5]int{2,1,9,4,5}
    sort.Ints(yang[:])
    fmt.Println(yang)
}
func main() {
    fmt.Printf("%T %T %T\n",'c',string('c'),[]byte(string('c')));
    fmt.Printf("%v %v %v",'c',string('c'),[]byte(string('c')));
    /*
       int32   string   []uint8
       99      c         [99]
    */
    var yang string = "ni hao a "
    for i :=0 ;i < len(yang) ; i++ {
        fmt.Println("%v",yang[i],string(yang[i]))
    }
    /*
    %v 110 n
    %v 105 i
    %v 32
    %v 104 h
    %v 97 a
    %v 111 o
    %v 32
    %v 97 a
    %v 32
    */
    test_sort()
}
Christian-health commented 5 years ago
package main

import "fmt"

func main() {
    var areaIntf interface{}
    var a float32 = 10
    areaIntf = a
    switch  t := areaIntf.(type) {
        case float32: fmt.Printf("Type float32 with value %v\n", t)
        case nil: fmt.Println("nil value: nothing to check?:")
        default: fmt.Printf("Unexpected type %T", t)
    }
    /*
       Type float32 with value 10
    */
}