package main import ( "fmt" ) type Student struct { id int name string } func main() { //方式一 s := Student{1, "yy"} fmt.Println(s) //方式二 s.id = 2 s.name = "yang" fmt.Println(s) }
注意:順序初始化,每個成員必須初始化,在初始化時,值的順序與結構體成員的順序保持一致。
package main import ( "fmt" ) type Student struct { id int name string } func main() { //方式一 s := Student{1, "yy"} fmt.Println(s) //方式二 s.id = 2 s.name = "yang" fmt.Println(s) }
注意:順序初始化,每個成員必須初始化,在初始化時,值的順序與結構體成員的順序保持一致。
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。