初始化构造函数中定义的实体集合,方便嵌套类型的遍历
2016-12-25 21:47
309 查看
class Programs { public static void OP() { Student[] stuinfo = new Student[] { new Student("HB001","Tom",'男',20,new List<Archement>(new Archement[]{new Archement("HB001","大学数学",88),new Archement("HB001","大学语文",88)})), new Student("HB002","Lucy",'女',23,new List<Archement>(new Archement[]{new Archement("HB002","大学数学",88),new Archement("HB002","大学语文",88)})), new Student("HB003","Peter",'男',27,new List<Archement>(new Archement[]{new Archement("HB003","大学数学",88),new Archement("HB003","大学语文",88)})), new Student("HB004","Bruce",'男',30,new List<Archement>(new Archement[]{new Archement("HB004","大学数学",88),new Archement("HB004","大学语文",88)})) }; foreach (var item in stuinfo) { Console.WriteLine("{0}\t{1}\t{2}\t{3}", item.StuID, item.StuName, item.StuSex, item.Age); foreach (var s in item.Score) { Console.WriteLine("{0}\t{1}", s.CourseName, s.Score); } } } } public class Student { public string StuID { get; set; } public string StuName { get; set; } public char StuSex { get; set; } public uint Age { get; set; } public List<Archement> Score { get; set; } public Student(string ID, string Name, char Sex, uint Uage, List<Archement> lst) { this.StuID = ID; this.StuName = Name; this.StuSex = Sex; this.Age = Uage; Score = new List<Archement>(); foreach (var item in lst) { this.Score.Add(item); } } } public class Archement { public string StuNo { get; set; } public string CourseName { get; set; } public double Score { get; set; } public Archement(string ID, string Name, double DScore) { this.StuNo = ID; this.CourseName = Name; this.Score = DScore; } }
相关文章推荐
- 稀疏自编码
- Qt信号与槽的自动
- 数据库冲突可串行化前趋图画法
- 需求分析中原型化方法
- java中transient关键字的作用
- 快速幂
- 6.2.4
- 纯Css实现三角形
- 安装Windows 和linux双系统失败导致Windows无法引导的解决方法
- 解释器模式
- 20145302张薇 《信息安全系统设计基础》课程总结
- 使用 Object.create实现js 继承
- Best Part
- shell软件工具设计的原则_转
- Eclipse导出SVN项目的时候,不再提示输入用户名,密码问题
- Oracle数据库SQL语言实战培训教程(全面、详细、案例、精讲)套餐
- HDU 程序设计竞赛题解(2016‘12)
- python面向对象二
- 小组作业(第五组)
- #173. 蚯蚓健身操