package main
import (
"fmt"
"strconv"
)
type Student struct {
name string
age int
}
type Class struct {
className string
students []Student
}
type School struct {
schoolName string
classes []Class
}
func main() {
var school=new(School)
school.schoolName="XXX大学"
for i:=0;i<10 ;i++ {
school.classes=append(school.classes,Class{className:"班级"+strconv.Itoa(i) })
for j:=0;j<30 ;j++ {
school.classes[i].students=append(school.classes[i].students,Student{"学生"+strconv.Itoa(j),10+j})
}
}
fmt.Println(school.schoolName)
for i:=0;i<10 ;i++ {
fmt.Println(school.classes[i].className)
for j:=0;j<30 ;j++ {
fmt.Println("姓名:"+school.classes[i].students[j].name+" 年龄:"+strconv.Itoa(school.classes[i].students[j].age))
}
}
}
Go 学校,班级,学生类的三级关系
最新推荐文章于 2020-04-10 18:09:31 发布