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)
}
注意:顺序初始化,每个成员必须初始化,在初始化时,值的顺序与结构体成员的顺序保持一致。
Go语言 之结构体初始化方式
阅读 80
2022-06-01
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)
}
注意:顺序初始化,每个成员必须初始化,在初始化时,值的顺序与结构体成员的顺序保持一致。
相关推荐
精彩评论(0)