<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                `"{" 換行: Opening Brace Can't Be Placed on a Separate Line ` 錯誤: ~~~ package main func main() { println("hello world") } ~~~ 報錯信息: ~~~ ./main.go:3:6: missing function body for "main" ./main.go:4:1: syntax error: unexpected semicolon or newline before { ~~~ 正確: ~~~ package main func main() { println("hello world") } ~~~ `定義未使用的變量: Unused Variables` 錯誤: ~~~ package main var str string func main() { var num int println("hello world") } ~~~ 報錯信息: `./main.go:6:6: num declared and not used` 正確: ~~~ package main var str string func main() { // var num int println("hello world") } ~~~ `import 但未使用: Unused Imports` 錯誤: ~~~ package main import ( "fmt" "os" ) func main() { println("hello world") } ~~~ 報錯信息: ~~~ ./main.go:4:2: imported and not used: "fmt" ./main.go:5:2: imported and not used: "os" ~~~ 正確: ~~~ package main import ( "fmt" _ "os" ) func main() { fmt.Println("hello world") } ~~~ `命名區分大小寫` 錯誤: ~~~ package main import "fmt" func main() { fmt.println("Hello world") } // 以下代碼都是不正確的: // Package main // iMport "fmt" // import "Fmt" // Func main() {} // Fmt.Println // fmt.println ~~~ 報錯信息: ~~~ ./main.go:6:2: cannot refer to unexported name fmt.println ./main.go:6:2: undefined: fmt.println ~~~ 正確: ~~~ package main import "fmt" func main() { fmt.Println("Hello world") } ~~~ `分號分行` 錯誤: ~~~ package main import "fmt" func main() { fmt.Println("Hello world") fmt.Println("Hi again") } ~~~ 錯誤信息: ./main.go:6:29: syntax error: unexpected fmt at end of statement 正確: ~~~ package main import "fmt" func main() { fmt.Println("Hello world") fmt.Println("Hi again") //解決以上問題,可以將上述的兩條語句放在兩行 fmt.Println("Hello world");fmt.Println("Hi again") //可以將兩條語句用分號結束 test() } func test() { //因此在Go語言中,分號能省則省,如果必須使用時,添加上也不會出錯。所以,如下代碼也是正確滴。 fmt.Println("Hello world");fmt.Println("Hi again"); }; ~~~ `無效的分號` 錯誤: ~~~ package main import "fmt";; func main() { fmt.Println("Hello world") } ~~~ 錯誤信息: ~~~ ./main.go:3:14: syntax error: non-declaration statement outside function body ~~~ 正確: ~~~ package main import "fmt"; func main() { fmt.Println("Hello world") } ~~~ 簡短變量定義方式只能在函數內部使用: Short Variable Declarations Can Be Used Only Inside Functions 錯誤: ~~~ package main str := "hello world" func main() { println(str) } ~~~ 報錯信息: `./main.go:3:2: syntax error: non-declaration statement outside function body` 正確: ~~~ package main func main() { str := "hello world" println(str) } ~~~ 重復定義 變量: Redeclaring Variables Using Short Variable Declarations 錯誤: ~~~ package main var num int var num int func main() { str := "hello world" str := "hello golang" println(str) } ~~~ 報錯信息: ~~~ ./main.go:4:5: num redeclared in this block previous declaration at ./main.go:3:5 ./main.go:8:6: no new variables on left side of := ~~~ 正確: ~~~ package main var num int var num2 int func main() { str := "hello world" str = "hello golang" println(str) } ~~~ 注意變量作用域: Accidental Variable Shadowing 錯誤: ~~~ package main var num int func main() { str := "hello world" if true { var b bool } println(num) println(str) println(b) } ~~~ 報錯信息: `./main.go:12:10: undefined: b` 正確: ~~~ package main var num int func main() { str := "hello world" if true { var b bool println(b) } println(num) println(str) // println(b) } ~~~ nil 不能賦值給 不明類型的變量和非指針類型的變量: Can't Use "nil" to Initialize a Variable Without an Explicit Type 錯誤: ~~~ package main var null string = nil func main() { null2 := nil println(null) println(null2) } ~~~ 報錯信息: ~~~ ./main.go:3:5: cannot use nil as type string in assignment ./main.go:6:8: use of untyped nil ~~~ 正確: ~~~ package main var null *string = nil func main() { var null2 *int null2 = nil println(null) println(null2) } ~~~ map 未初始化 直接使用: Using "nil" Slices and Maps------interfaces, functions, pointers, maps, slices, and channels 錯誤: ~~~ package main import ( "fmt" ) func main() { var m map[int]int m[1] = 1 fmt.Println(m) } ~~~ 報錯信息: ~~~ panic: assignment to entry in nil map ~~~ 正確: ~~~ package main import ( "fmt" ) func main() { var m map[int]int m = make(map[int]int) m[1] = 1 fmt.Println(m) } ~~~ map 只有 len操作, 沒有 cap 操作: Map Capacity 錯誤: ~~~ package main import ( "fmt" ) func main() { m := map[int]string{1: "a", 2: "b", 3: "c"} cap := cap(m) fmt.Println(cap) } ~~~ 報錯信息: ~~~ ./main.go:9:12: invalid argument m (type map[int]string) for cap ~~~ 正確: ~~~ package main import ( "fmt" ) func main() { m := map[int]string{1: "a", 2: "b", 3: "c"} len := len(m) fmt.Println(len) } ~~~
                  <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>

                              哎呀哎呀视频在线观看