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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                > ### 結構 struct ~~~ package main import "fmt" // Go提供的結構體就是把使用各種數據類型定義的不同變量組合起來的高級數據類型 type Person struct { Name string Age int } func main() { fmt.Println(Person{"A", 18}) fmt.Println(Person{Name: "B", Age: 19}) fmt.Println(Person{Name: "C"}) } ~~~ > ### 例子二 ~~~ package demo11 import ( "fmt" "encoding/json" ) type User struct { name string age int } func NewUser(name string, age int) *User { var user *User = &User{name, age} return user } type exam struct { number1 int number2 int number3 int number4 int } type student struct { grade int subject string *people } type people struct { name string age int } type message struct { Id int `json:"user_id",db:"user_id"` Title string `db:"user_title"` Content1 string content2 string //小寫私有, 別的包是無法訪問的 } func Demo11() { //new(User) 和 &User{} 本質上是一樣的,都是返回結構體地址 var user1 *User = new(User) fmt.Printf("%p\n", user1) var user2 *User = &User{} fmt.Printf("%p\n", user2) var user3 User fmt.Printf("%v\n", user3) //結構體里的字段占用一段連續的內存空間 //%p 十六進制表示,前綴 0x var exam *exam = &exam{} fmt.Printf("%p\n", &exam.number1) fmt.Printf("%p\n", &exam.number2) fmt.Printf("%p\n", &exam.number3) fmt.Printf("%p\n", &exam.number4) //結構體沒有構造函數, 可以自己實現 //構造函數 ,是一種特殊的方法。主要用來在創建對象時初始化對象, 即為對象成員變量賦初始值 var user4 *User = NewUser("張三", 25) fmt.Printf("%v\n", user4) //匿名字段默認采用類型名作為字段名 //結構體嵌套 var student1 student student1.people = &people{ name: "李四", age: 15, } fmt.Printf("%#v \n %#v \n", student1, student1.people) var student2 student //未初始化默認指向空的內存 student2.people = &people{} student2.name = "王五" student2.age = 16 fmt.Printf("%#v \n %#v \n", student2, student2.people) //tag是結構體的原信息, 可以在運行時通過反射的機制讀取出來 msg1 := &message{ Id: 1, Title: "標題1", Content1: "內容1", content2: "內容2", } data, _ := json.Marshal(msg1) fmt.Println(string(data)) } ~~~
                  <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>

                              哎呀哎呀视频在线观看