结构体
type StructName struct{
FieldName type
}简单示例:定义一个学生结构体
package main
import "fmt"
type Student struct {
Age int
Name string
}
func main() {
stu := Student{
Age: 18,
Name: "name",
}
fmt.Println(stu)
// 在赋值的时候,字段名可以忽略
fmt.Println(Student{20, "new name"})
return
}结构体中可以内嵌结构体
结构体是可以比较的
结构体内嵌匿名成员
最后更新于