zoukankan      html  css  js  c++  java
  • 初始化构造函数中定义的实体集合,方便嵌套类型的遍历

    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}	{1}	{2}	{3}", item.StuID, item.StuName, item.StuSex, item.Age);
                    foreach (var s in item.Score)
                    {
                        Console.WriteLine("{0}	{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;
            }
        }
  • 相关阅读:
    中值滤波器(平滑空间滤波器)基本原理及Python实现
    均值滤波器(平滑空间滤波器)基本原理及Python实现
    使用bibtex为latex论文添加参考文献
    【Linux】日志
    【Linux】常用命令
    【Oracle】查看表大小
    【Oracle】to_date兼容YYYYMMDDHH24MISS与YYYY-MM-DD HH24:MI:SS
    【Mybatis】Lexical error
    【JS】上传插件配置
    【2020-10-06】年年岁岁做计划,岁岁年年完不成!
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/6220669.html
Copyright © 2011-2022 走看看